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.
| Error | What Cloudflare saw | Where to look first |
|---|---|---|
| 520 | A connection, then an empty, invalid or reset response | Origin application and web server error logs |
| 521 | The origin actively refused the TCP connection | Is the web server running; does the firewall allow Cloudflare |
| 522 | No TCP connection within Cloudflare's time limit | Server load, firewall dropping packets, wrong DNS record |
| 524 | A connection, but no HTTP response within 100 seconds | Slow 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.
# 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 AFix it
- 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.
- Allow Cloudflare's IP ranges in the host firewall, the cloud security group and any rate limiter, and make sure nothing silently drops them.
- Correct the DNS records in Cloudflare; remove AAAA records if the origin has no working IPv6.
- Check the host with your provider if even direct connections time out.
- Watch connection time after the fix: a rising
time_connectis the early warning for the next 522.
Catch it before your visitors do
Cloudflare's error pages hide the cause, so measure both sides:
- Check the public URL through Cloudflare with an uptime monitor from several regions. That is what visitors get, 52x errors included.
- 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.
- 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.
- 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.
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
- Is Cloudflare down? Live status: checked every few minutes, with outage history.
- Website down checker: Is it down for everyone or just me? Check any site now.
- Open port checker: Is a TCP port open, closed or filtered from the internet?
Related reading
- Error: connect ETIMEDOUT: What ETIMEDOUT means, how it differs from ECONNREFUSED, the usual causes such as firewalls, security groups and wrong IPs, and how to set timeouts.
- Cloudflare error 1016 "Origin DNS error": how to fix it: Fix Cloudflare error 1016 Origin DNS error: CNAME records pointing to names that do not resolve, deleted origins and load balancer pools, with checks.
- Cloudflare error 530: how to fix it: Fix Cloudflare error 530, usually shown with error 1033 (Argo Tunnel error) or 1016: stopped cloudflared tunnels, deleted tunnels and origin DNS problems.
- Nginx "upstream timed out (110)": how to fix it: Fix Nginx upstream timed out (110: Connection timed out) while reading response header: find the slow request, tune proxy timeouts and fix the backend.
- HikariCP "Connection is not available": how to fix it: Fix HikariCP Connection is not available, request timed out: use leak detection, size the pool sensibly, avoid long transactions and read pool metrics.
- Cloudflare error 1015 "You are being rate limited": how to fix it: Fix Cloudflare error 1015 "You are being rate limited": what triggers rate limiting rules, how long blocks last, and how site owners tune them.
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.