0

I recently inherited administration over 2 Nginx boxes in AWS and am very unfamiliar with how PHP-FPM works (and doens't work). I recently integrated Keen.IO for backend user logging, using:

fastcgi_finish_request();

in php to finish the request and then continue on to log to Keen. This seemed to be working good except for some higher latency which I assume the user was not experiencing because they had already disconnected.

Today however, as traffic built, we started getting 502 gateway errors, and both servers have the following error:

[error] 2356#0: *70245 upstream sent unexpected FastCGI record: 3 while reading response header from upstream, client: (ADDRESS), server: igun-api-slaves.crimson-moon.com, request: "GET (Address)", upstream: "fastcgi://unix:/var/run/php-fpm/product1.socket:", host: "ADDRESS"

This happens on all of our pages, not just the ones I modified with logging. I am completely lost as this is all new for me. What exactly does this error mean?

-- EDIT

I see now in AWS cloud watch that the errors have been coming ever since the code was edited, not just when the traffic built.

David
  • 103
  • 5

2 Answers2

2

The log message means that PHP-FPM is sending a record type ID that nginx doesn't understand. It turns out, as you might have guessed, that record type 3 corresponds to FCGI_END_REQUEST. Thus, it would appear that nginx's FCGI support is incomplete, in that it doesn't recognise and correctly handle this record type.

I'd suggest either cracking open your editor and patching nginx, or else stop calling fastcgi_finish_request(), and work out some other way of achieving what you want to do.

womble
  • 95,029
  • 29
  • 173
  • 228
  • There appears to be no other way of nicely ending the users request. Is this from the need to compile nginx with a different flag? Also, this doesn't makes sense why this is getting 502 errors on pages without logging or fastcgi_finish_request() calls. After adding this, these 502 errors happen intermittently on all my pages. After removing them and rolling back the code, it stops happening on all pages. – David Aug 08 '15 at 12:57
  • I can only answer based on the information you've given. The log entry you provided tells me what I gave in my answer. If you've got other diagnostic information, it may shed more light on your situation. – womble Aug 08 '15 at 22:17
  • Figured it out. It is a bug in PHP - See my answer below – David Aug 10 '15 at 04:10
0

This error appears to be caused by a bug in PHP which does not correctly handle fastcgi_finish_request()

https://bugs.php.net/bug.php?id=67583

This can be worked around until patched by turning off fastcgi_keep_conn in the Ngynx settings.

David
  • 103
  • 5