521 from cloudflare worker to our netlify site

We have some cloudflare workers that request content from Netlify. In the last 7 days we are seeing 521 response codes from Netlify. Is there something we can do to stop this?

Hi, @Tudodesk. Our support team cannot answer questions about what happens at Cloudflare because we have zero visibility into their systems or errors. Our service does not return 521 statuses (unless you proxy to a third-party system in which case it might return a 521 and we simply proxy that status code).

My understanding of 521 statuses at Cloudflare is that this means the origin cannot be reached so it looks like the configuration at Cloudflare is wrong. What does Cloudflare have to say about the 521 statuses?

If you want out help troubleshooting, we need the following details:

  • which site at Netlify is this about (the site subdomain or API ID for example)
  • how is Cloudflare configured to proxy to Netlify (the more details the better)

If there are other questions for us, please let us know.

Hi Luke,

Thanks for replying so for example and from what I am aware this has happened last 7 days on 2-3 sites:


I understand the cloudflare part, I wanted to ask Netlify if any issue was unexpected on their side or if we are doing something wrong on our end via Cloudflare.

So what we do is use cloudflare workers to effectively map a url on cloudflare to netlify.

When we do this we use caching in the worker - effectively if I am correct the worker grabs the content from Netlify and caches it so further calls do not hit netlify servers.

What we are getting is 521 origin not responding codes for some resources.

response = await fetch(new_url,{cf: { cacheTtl: 21600,cacheEverything: true}});
html = await response.text();

// Return modified response.
var res = new Response(html, {
status: response.status,
statusText: response.statusText,
headers: response.headers
res.headers.set(“cache-control”, “public, max-age=86400, must-revalidate”);
return res;

Our worker takes the request, modifies the URL, fetches it from netlify, and returns it adding some cache headers. I am not sure if the headers are causing the issue?

I am also not sure why we don’t just use a redirect rule in cloudflare.

Hi, @Tudodesk. We need the following information to track down the requests which are timing out.

  • the full URL requested at Netlify
  • the IP address making the request
  • the IP address that the request is sent to
  • the date, time, and timezone of the request

Can you send us that information?