Search code examples
phpnginxfastcgigoogle-cloud-runfpm

Google Cloud Run website timeouts when content length is between 4013-8092 characters. What is going on?


This issue happens on a pure PHP files served by Nginx & PHP-FPM. I've stumbled upon this issue while developing my website using Symfony but the problematic content length range is 3702-15965 for that (I wonder why it's different than vanilla PHP).

What I've tried so far:

  • Timeout duration is 15 seconds but I've tried increasing it to 300 seconds and it still timeouts. So I'm guessing it's infinite loopy thing.
  • It doesn't look like it's resource related because it works even if content length is 5 million characters.
  • Created various tests with different characters to see if I can cause changes to the problematic content length range. Answer is no, range stayed same for all my tests.
  • I have tried disabling gzip. It didn't change the length range but the response changed. Gzip enabled response: "upstream request timeout" | Gzip disabled response: Completely blank

Notes:

  • This issue doesn't exist on my localhost.
  • It rarely opens the page normally. I can't reproduce this consistently.
  • There are no errors in Nginx, PHP or GCR logs besides the "request timed out" lines.

Any help is appreciated. Thanks.


Solution

  • Funnily enough, I've solved the issue while writing the question. Adding fastcgi_buffering off; to Nginx config fixes the issue.

    But I still don't understand what was the problem and why disabling buffering fixed it. So if anyone can explain it I don't mind marking that answer as solution.