HTTP 520 for ajax call


Recently (few weeks ago) I’ve noticed strange Cloudflare behaviour. I have a phpBB forum with simple chat inside. This chat works with ajax. Every 5 seconds browser sends ajax GET request to refresh the chat and to receive new messages. Most of the times browser receives HTTP 200 response, but sometimes, after 10 to 15 minutes of refreshing, browser receives HTTP 520 error response.

I have checked that, when this happens, my server does not even receives the request from Cloudflare. Cloudflare just responds with 520 without contacting origin server.
When I’m connected to my server directly, without Cloudflare, this problem does not exist.

Do you know what could be the reason of that behaviour?

Best regards

520s typically mean your origin server did something unexpected. Often this can be triggered by the origin server resetting the TCP connection before the request is completed, but it can also be caused by the origin returning too many HTTP response headers.

In your case, I have checked our logs and the error message is:

upstream prematurely closed connection while reading response header from upstream

Unfortunately Cloudflare can’t really know why your server does this, only that it does. So you would need to check your origin server access & error logs when these 520 errors occur to understand why your origin server is resetting the TCP connection prematurely here.

Thank you for your response. But I have observed that these connections are not in logs on our side. Ok, it may happen that our Apache won’t log them. The strange thing is we did not replicated the error when we were connected directly to our server. We really tried it and we did not “succeed” with the error.

I must also say that this problem occurs only with one URL (/refresh).

Is it possible that it is some anti-bot mechanism maybe?

If it was a security feature on Cloudflare you’d see a Cloudflare branded block page, a 520 means your origin disconnected. Unfortunately we can’t know exactly why - so you would have to run more tests on your server to understand why it is dropping the connection in this case.

Typically it can mean the web server itself is crashing, or if it’s a dynamic scripting language like PHP, it could be the PHP module itself is crashing. But the best thing to do is to check all of your logs here and talk to your host.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.