What is the Workers timeout?

Got a request to implement the IDLE command into my CF Workers IMAP lib. That would mean keeping the TCP connection alive for longer periods of time. From what I understand Cloudflare bills based on CPU time, rather than the total time it took for the Worker to finish, so in terms of billing it shouldn't be sky high. The problem is that it is definitely not the use case for a Worker (well, the exact opposite really). Theoretically, though, after what time would the worker process be terminated?
9 Replies
exerra.xyz
exerra.xyzOP6mo ago
Essentially, how long can a Worker idle connected to a TCP socket? I imagine like a minute or so is fine, right? Ah, wait, finally managed to find the limits.
exerra.xyz
exerra.xyzOP6mo ago
Cloudflare Docs
Limits
Cloudflare Workers plan and platform limits.
exerra.xyz
exerra.xyzOP6mo ago
Theoretically infinite, however a few times a week the runtime is updated.
Chaika
Chaika6mo ago
The client has to stay connected
When the client disconnects, all tasks associated with that client request are canceled. Use event.waitUntil() to delay cancellation for another 30 seconds or until the promise passed to waitUntil() completes.
exerra.xyz
exerra.xyzOP6mo ago
Yeah I just thought of that What about cron triggers?
Chaika
Chaika6mo ago
Scheduled Workers (Cron Triggers) have different limits on CPU time based on the schedule interval. When the schedule interval is less than 1 hour, a Scheduled Worker may run for up to 30 seconds. When the schedule interval is more than 1 hour, a scheduled Worker may run for up to 15 minutes.
exerra.xyz
exerra.xyzOP6mo ago
All right, thank you!
Chaika
Chaika6mo ago
that's kind of conflating cpu time and duration there but I believe they're the same for that aspect. Docs only explicitly state 15 mins for cron though def not build for superr long lived connections eitherway
exerra.xyz
exerra.xyzOP6mo ago
yeahh, def not I mean it is kiiinda possible, just not practical in any way

Did you find this page helpful?