Ticket #1041: lighttpd-1.4.13.patch-FastCGI-EAGAIN

File lighttpd-1.4.13.patch-FastCGI-EAGAIN, 1.5 kB (added by colin.stephen@…, 20 months ago)

Patch to handle EAGAIN in mod_fastcgi.c

Line 
1diff -Naur lighttpd-1.4.13/src/mod_fastcgi.c lighttpd-1.4.13-patched/src/mod_fastcgi.c
2--- lighttpd-1.4.13/src/mod_fastcgi.c   2006-10-05 11:22:32.000000000 +0100
3+++ lighttpd-1.4.13-patched/src/mod_fastcgi.c   2007-02-18 16:55:58.000000000 +0000
4@@ -2365,6 +2365,7 @@
5         * check how much we have to read
6         */
7        if (ioctl(hctx->fd, FIONREAD, &toread)) {
8+               if( errno == EAGAIN ) return 0;
9                log_error_write(srv, __FILE__, __LINE__, "sd",
10                                "unexpected end-of-file (perhaps the fastcgi process died):",
11                                fcgi_fd);
12@@ -2375,12 +2376,23 @@
13 
14        if (toread > 0) {
15                buffer *b;
16+               chunk *cq_first = hctx->rb->first;
17+               chunk *cq_last = hctx->rb->last;
18 
19                b = chunkqueue_get_append_buffer(hctx->rb);
20                buffer_prepare_copy(b, toread + 1);
21 
22                /* append to read-buffer */
23                if (-1 == (r = read(hctx->fd, b->ptr, toread))) {
24+                       if( errno == EAGAIN ) {
25+                               /* roll back the last chunk allocation,
26+                                   and continue on next iteration        */
27+                               buffer_free(hctx->rb->last->mem);
28+                               free(hctx->rb->last);
29+                               hctx->rb->first = cq_first;
30+                               hctx->rb->last = cq_last;
31+                               return 0;
32+                       }
33                        log_error_write(srv, __FILE__, __LINE__, "sds",
34                                        "unexpected end-of-file (perhaps the fastcgi process died):",
35                                        fcgi_fd, strerror(errno));
36@@ -2393,6 +2405,7 @@
37                b->used = r + 1; /* one extra for the fake \0 */
38                b->ptr[b->used - 1] = '\0';
39        } else {
40+               if( errno == EAGAIN ) return 0;
41                log_error_write(srv, __FILE__, __LINE__, "ssdsb",
42                                "unexpected end-of-file (perhaps the fastcgi process died):",
43                                "pid:", proc->pid,