How to stop Cloudflare from caching 522 errors?

How do I stop Cloudflare from caching images if the server was temporarily unavailable? Basically, I have several images that are displaying a 522 error, and it’s because that response seems to be the cached response.

I wrote a temporary page rule to bypass that image in the Cloudflare cache and go straight to the server and voila, the image loads right up. I turn the bypass back off for that image, and voila, the 522 error comes right back.

So what appears to have happened is that the server was down for a minute during which time Cloudflare attempted to fetch that image. It was unable to reach the server so it generated, and then cached, a 522 error. I don’t want the image added to the cache if it is a 522 error. It should be bypassing the cache until it actually gets a response.

Is it somehow possible to always bypass the cache/don’t put files in a cache if they generated an error? How do I accomplish that?

Just to clarify, I can fix the 522 for any specific resource by ensuring that it is back online and then manually clearing or bypassing the Cloudflare cache for that resource. However, I want to systematically prevent this from happening in the future. It should NOT be putting errors into the cache in the first place. It should be a “MISS” and try for the resource again until it has something valid to put into the cache.

This is becoming increasingly frustrating. My best guess now is that there is a node somewhere along Cloudflare’s path to my server that is blocking the request, because every single time I find an image or link that Cloudflare says is timing out with a 522 error, I bypass the Cloudflare cache and the link works just as it should.

Guys Hello , I have This Problem 522 time out , I am using iPhone 6 and I want to open a private site but it’s not working ,

Those errors are not cached. Did you check the server logs if this requests hit your server and If it responds in time?
Do you use Always Online?

Do you have an example link for us?

Start your own thread please, this is a different issue.

It’s happening on nearly every single page on my site. It’s a fairly image heavy site, so you’ll go to any random page (like the home page), and half of the images are gone.

I’ve checked with my hosting provider (in Asia) and they’ve shown me screenshots that the images are loading just fine for them. So it appears that the Chicago node (if I can call if that, not sure of the technical term) of the Cloudflare network which I’m connecting to is unable to reach the server, but the nodes closer to the server are able to connect to it just fine.

We have checked the logs on the server. We have no blocked or dropped requests on the server. I have all of the Cloudflare IP addresses whitelisted.

So my assumption is that from the Chicago node to the Origin, it probably passes through (for sake of argument, let’s say a dozen) a dozen other routers. I’m wondering if the site is blocked, has an invalid DNS record, or some other issue that is dropping the connection midway between Cloudflare’s node and my origin.

I’m also inclined to believe that some sort of caching may be happening because I’ve set up a couple of subdomains that behave as an exact alias of the main domain. In some instances, I get a 522 error for one resource and not for the other:

Both are on the same server. Both access the exact same process or resource on the server. Both are being accessed by Cloudflare. Etc. One works, and one won’t.

check your main webserver, and if you receive another 522 error, please check the headers for CF-Cache-Status, if it’s a Cloudflare 522, it’s not cached and you have to wait. If it’s a nginx or apache or other 522, it could be cached. I have a guide of protecting against ddos here GitHub - scaredos/cfresearch: A repository containing research regarding various Anti-DDoS systems. (CloudFlare)

The 522 is 100% not being generated by my server. It is NOT from nginx or apache. It is 100% from Cloudflare and only for some random resources.

The documentation says that it will generate this if it doesn’t respond for 15 seconds, then why is it being generated in less than 3 seconds when I run cacheless pings on it?

OK. A few things now since it is like fishing in the gloomy.

Please provide a URL if you feel comfortable to make it public, or post the response header. 522 is not cached by Cloudflare. You also didn’t anwer my question about Always Online. Or I missed the answer.

We don’t have access to your account, so we rely on this things, or logs or whatever could help.

If you don’t feel comfortable to make this things public, you should open a support ticket. They may request a HAR file

1 Like

As the MVP said, CloudFlare errors are not cached, as their headers specifically instruct no caching. So, this means your web server is either constantly timing out or just not responding to the http(s) request.

This topic was automatically closed after 30 days. New replies are no longer allowed.