upstream split a header line in FastCGI records

Igor Sysoev is at
Tue Aug 4 13:30:30 MSD 2009

On Mon, Aug 03, 2009 at 03:31:37PM -0400, matrix wrote:

> For the past 10 hours I have been trying to find out why my application sometimes generates a "502 Bad Gateway" error and sometimes do not, even though the page output should be nearly identical. The error is described by nginx as "upstream prematurely closed connection while reading response header from upstream" without debug and as "upstream split a header line in FastCGI records" with debug.
> This only happens when I'm using FirePHP, a debugging class for PHP, which sends information to browser using headers. It would appear that it only happens when the amount of output from FirePHP reaches a certain value that the error happens, as I don't get any errors if FirePHP outputs only a small amount of debug information.
> The error still happens if I create a new PHP script with just FirePHP loaded and use it to output a lot of random strings (preset in script). Yet, the error still only happens sometimes (about 50% chance).
> I have tried the latest versions of all 3 branches of nginx (legacy, stable and development) with the same results. PHP is 5.3.0, with php-fpm (spawn-fcgi causes same error) and unix sockets as the link between PHP and nginx (TCP connection causes same error).
> My fastcgi settings in nginx are:
> fastcgi_connect_timeout 60;
> fastcgi_send_timeout 180;
> fastcgi_read_timeout 180;
> fastcgi_buffer_size 128k;
> fastcgi_buffers 4 256k;
> fastcgi_busy_buffers_size 256k;
> fastcgi_temp_file_write_size 256k;
> fastcgi_intercept_errors on
> I've ran nginx in debug mode and got logs of a good page and of a bad page:
> Good:
> Bad: (things go bad at line 250)
> I hereby request help. Is it a nginx problem or is it something else?

Try the attached patch.

Igor Sysoev
-------------- next part --------------
Index: src/http/modules/ngx_http_fastcgi_module.c
--- src/http/modules/ngx_http_fastcgi_module.c	(revision 2329)
+++ src/http/modules/ngx_http_fastcgi_module.c	(working copy)
@@ -1439,6 +1439,10 @@
         part->start = part_start;
         part->end = u->buffer.last;
+        if (u->buffer.pos < u->buffer.last) {
+            continue;
+        }
         return NGX_AGAIN;

More information about the nginx mailing list