Worker Timeout and AbortController Cancellation Boundary
0 reputation · 26 Aug 2022, 10:29 UTC
Goal
Determine whether AbortController-triggered cancellation in Cloudflare Workers terminates all in-flight operations before the runtime timeout, or whether KV writes may complete after the threshold.
The free plan enforces a 10-second CPU time limit; paid plans extend this to 30 seconds. The runtime does not expose a built-in cancellation mechanism; developers use the native AbortController or early returns. However, the runtime may continue background work until the timeout expires, and side effects in flight such as outbound fetches or KV writes may not be immediately terminated when cancellation triggers. This creates uncertainty about the boundary between cancellation intent and timeout enforcement, especially across plan tiers and when the cf-timeout header is set at the API Gateway.
- When AbortController.signal triggers, does the runtime abort queued operations immediately, or permit in-flight fetches and KV operations within the remaining timeout window?
- For paid plans with a 30-second timeout, does cancellation behavior differ from the free plan's 10-second limit, and how does the cf-timeout header interact with Worker-internal timeout enforcement?
- When an AbortController abort causes a Worker to exit, are KV writes in progress guaranteed to be rejected, or can they succeed depending on event loop timing?