522 Error when using cloudflare workers

We are using cloudflare workers to call OpenAI and sometime the calls can take minutes to complete. Is there any way to send a heartbeat or any other signal to the worker that the out bound request is still alive and should not be timed out?
10 Replies
Chaika
Chaika14mo ago
If it a 524 or a 522? If it's a 524 - timed out, Cloudflare has a 100 second timeout on receiving a response that can only be raised by Enterprise. If you can stream the response you could get past that
Justin
Justin14mo ago
We are on Enterprise. But we are getting a 522
Chaika
Chaika14mo ago
Are you talking about the HTTP Status code, or the status code it gives you on the error page? Cloudflare has a few 1xxx errors for Workers resources exceeded and such, I don't know what normal http status code it would give you for those off the top of my head.
Justin
Justin14mo ago
This is what we are getting from our customers
Chaika
Chaika14mo ago
hmm yea you'd want more info then that. If you just have a simple worker that proxies requests to OpenAI, I believe that could be OpenAI's API timing out
Justin
Justin14mo ago
hmm that makes sense, but wouldn't the "fetch" return an error, not the entire worker in that case then?
Chaika
Chaika14mo ago
522 is more specific then 524, from the docs: https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/#error-522-connection-timed-out
Error 522 occurs when Cloudflare times out contacting the origin web server. Two different timeouts cause HTTP error 522 depending on when they occur between Cloudflare and the origin web server: Before a connection is established, the origin web server does not return a SYN+ACK to Cloudflare within 15 seconds of Cloudflare sending a SYN. After a connection is established, the origin web server doesn’t acknowledge (ACK) Cloudflare’s resource request within 90 seconds.
If you're just responding with whatever fetch gives you, it would just echo that error up. ChatGPT's API is using Cloudflare as well
Justin
Justin14mo ago
Hmm I dont think so, because when users switch off our proxy they do not experience this issue 🤔 is this helpful?
Chaika
Chaika14mo ago
Switching from going through Cloudflare to ChatGPT API direct is a big difference. If some long requests work, but some don't, it sounds like me like their API is the issue. You could add additional logging/information on what the subrequest gets back. 522 isn't what I would expect though if it was just a simple timeout. If you are Enterprise, as well, you can reach out to chat/enterprise support, and they would be able to see more then I can hopefully Kind of, it's not a Worker error. Also careful, you leaked their IP ouch discord is having issues now lol (<https://discordstatus.com/incidents/tvbxxjf5p2kl), and not letting me edit my messages. If it was a simple timeout, I'd expect a 524 and a hard cutoff at 100 seconds. You could raise that anyway if you are on Enterprise with a simple API Call (https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/#error-524-a-timeout-occurred), but I'm guessing you are streaming the response back (via returning fetch or Response.body, and ChatGPT is streaming the response to you), which should be fine
Justin
Justin14mo ago
Thanks for your help So - this particular one is not being streamed
Want results from more Discord servers?
Add your server