Skip to content

Troubleshooting guide

Cloudflare error 522: connection timed out

A 522 means Cloudflare knocked and nobody answered: the TCP connection to your server never completed. The server is either too busy, unreachable, or silently dropping Cloudflare's packets.

5 min read10 sectionsUpdated

On this page

Key points

  • 522 = the TCP handshake with the origin did not finish in time.
  • Overload is the first suspect: CPU, memory or connection limits maxed out.
  • A firewall that drops (rather than rejects) Cloudflare's traffic produces 522, not 521.
  • A wrong or stale DNS record sends Cloudflare to an address where nothing answers.

What error 522 means

To serve a request Cloudflare first completes a TCP handshake with your origin. If the origin does not answer within Cloudflare's limit, the visitor gets 522. No HTTP request was sent yet, so your web server's access log usually shows nothing for these requests.

ErrorWhat Cloudflare sawWhere to look first
520A connection, then an empty, invalid or reset responseOrigin application and web server error logs
521The origin actively refused the TCP connectionIs the web server running; does the firewall allow Cloudflare
522No TCP connection within Cloudflare's time limitServer load, firewall dropping packets, wrong DNS record
524A connection, but no HTTP response within 100 secondsSlow requests: long queries, reports, exports, uploads

The usual causes

  • The server is overloaded. CPU at 100%, memory exhausted and swapping, or the web server's accept queue is full, so new connections wait until they time out.
  • Packets are dropped silently. A firewall, security group or rate limiter that drops packets (instead of rejecting them) makes connections time out.
  • The DNS record is wrong. The A or AAAA record in Cloudflare points to an old server, a private address or an IP that changed.
  • Network problems between Cloudflare and your host, or a host that is down entirely.
  • An IPv6 record without IPv6 service on the origin.

Confirm it

bash
# load and memory on the origin
uptime && free -m
# connections waiting in the queue (look at Recv-Q on the listening sockets)
sudo ss -ltn '( sport = :443 )'
# can you connect directly, and how long does it take?
curl -s -o /dev/null -w 'connect=%{time_connect}s total=%{time_total}s\n' --resolve example.com:443:203.0.113.10 https://example.com/
# what does DNS in Cloudflare point to?
dig +short example.com A

Fix it

  1. Relieve the load: scale up or out, add caching for expensive pages, restart workers that leak memory, raise worker and connection limits where they are the bottleneck.
  2. Allow Cloudflare's IP ranges in the host firewall, the cloud security group and any rate limiter, and make sure nothing silently drops them.
  3. Correct the DNS records in Cloudflare; remove AAAA records if the origin has no working IPv6.
  4. Check the host with your provider if even direct connections time out.
  5. Watch connection time after the fix: a rising time_connect is the early warning for the next 522.

Catch it before your visitors do

Cloudflare's error pages hide the cause, so measure both sides:

  1. Check the public URL through Cloudflare with an uptime monitor from several regions. That is what visitors get, 52x errors included.
  2. Check the origin directly with a second monitor on the origin's address or a health endpoint that bypasses Cloudflare. If only the first one fails, the problem is between Cloudflare and your server; if both fail, it is the server.
  3. Alert on the status code, not only on "down". A rule for any 52x response on the public check tells you which of the four errors it is before anyone opens a log.
  4. Keep the CF-Ray ID. It is in the error page and in the cf-ray response header; Cloudflare support and your own logs can be matched with it.

With APM on the origin you can also see the request that took 100 seconds behind a 524, instead of guessing.

Frequently asked questions

Why do I see 522 but my server logs are empty?

The TCP connection never completed, so no HTTP request reached the web server and nothing was logged. Look at system load, firewall logs and connection queues instead.

Is 522 caused by Cloudflare?

Almost always it is the origin or the network to it. Cloudflare-side incidents are listed on its status page; if your origin answers direct connections quickly, check firewall rules for Cloudflare's ranges.

Can a DDoS cause 522?

Yes, if traffic reaches the origin directly or the origin is overwhelmed. Make sure the origin only accepts traffic from Cloudflare so the proxy can absorb the attack.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.