Intermittent Cloudflare 502 (HTML page) on REST API via Seoul (ICN) edge — not in API logs #52588
Replies: 3 comments
|
Here is a technical breakdown of what is happening under the hood and why you must be careful with write retries. 1. Why does Cloudflare return an HTML 502 that does not appear in Supabase logs?When Cloudflare serves its own HTML "502 Bad Gateway" page (identifiable by the Cloudflare branded HTML and a
2. Can a Cloudflare 502 be treated as "never reached PostgREST" (safe for write retries)?Short answer: No, you should not assume the write never reached the database. While most 502s occur during the initial TCP/TLS handshake before any bytes are transmitted, a 502 is also returned in a second, dangerous failure mode:
If you blindly retry non-idempotent writes ( 3. Recommended Remediation & Architecture
|
|
tempting, given the 200 ms retry nearly always works, but i wouldn't read it as "never reached postgrest" a 502 only says a proxy got an invalid response from upstream, not whether the write was applied. rfc 9110 says not to auto-retry a non-idempotent request unless you know it's idempotent or can tell the original never ran. for writes that already got a 502, i'd look them up by a stable business or operation key before replaying anything going forward, i'd save a unique operation key in the same transaction as the side effect and its result, and have a retry with an existing key return that saved result. keep the key non-null, since nulls don't clash under a unique constraint by default i can't tell whether seoul has a known issue. for the ticket:
|
|
If the 502 response is generated by Cloudflare and the request never appears in your API logs, I would investigate the connection between the Cloudflare edge and the origin server first. Here are a few troubleshooting steps: 1. Check the Cloudflare Ray ID Capture the 2. Compare successful and failed responses Record these headers:
Check whether failures consistently come from the ICN edge. 3. Check origin connectivity Review origin server logs, load balancer logs, firewall rules, and TLS handshake errors. The request might fail before reaching the API application. 4. Test the origin directly If possible, send the same request directly to the origin while preserving the correct Host header and TLS SNI. Compare the result with the Cloudflare-proxied request. 5. Check Cloudflare error details Inspect the full 502 HTML response and its Ray ID. Different 502 error messages can indicate different failure points. Could you share:
These details should help narrow down whether this is an edge-to-origin connectivity issue or an origin-side failure. Avoid sharing API keys, cookies, or other sensitive credentials. |
Uh oh!
There was an error while loading. Please reload this page.
Is anyone else in the Seoul / ap-northeast-2 region seeing this?
Setup
Symptom
return an HTML "502 Bad Gateway" page from Cloudflare, not a PostgREST error.
periods, so the requests seem to fail before reaching the gateway.
so it does not look load-related.
retry also returned 502.
Questions
that retrying writes (POST/PATCH/DELETE/RPC) is safe?
A support ticket is open as well. I'm asking here to see whether others have
the same problem.
All reactions