workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

Workers-for-Platforms workers can "brick" themselves after running out of CPU time.

Open dmaretskyi opened this issue 2 weeks ago • 0 comments

What versions & operating system are you using?

System: OS: macOS 15.6.1 CPU: (16) arm64 Apple M4 Max Memory: 2.01 GB / 48.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.4.1 - /Users/dmaretskyi/.proto/tools/node/24.4.1/bin/node npm: 11.4.2 - /Users/dmaretskyi/.proto/tools/node/24.4.1/bin/npm pnpm: 9.15.4 - /Users/dmaretskyi/.proto/shims/pnpm bun: 1.3.3 - /Users/dmaretskyi/.proto/shims/bun Deno: 2.5.6 - /Users/dmaretskyi/.proto/shims/deno npmPackages: @cloudflare/vitest-pool-workers: 0.10.5 => 0.10.5 @cloudflare/workers-types: 4.20251106.1 => 4.20251106.1 wrangler: 4.49.0 => 4.49.0

Please provide a link to a minimal reproduction

Describe the Bug

We are deploying simple test worker to a dispatch namespace:

export default {
  async fetch(request: Request, env: Env) {
    const { iterations } = JSON.parse(await request.body.json());

    let a = 0n;
    let b = 1n;
    for (let i = 0; i < iterations; i++) {
      a += b;
      b = a - b;
    }
    
    return new Response(JSON.stringify({ result: a.toString() }), {
      headers: { "Content-Type": "application/json" },
    });
  },
};

Running this with a high iteration count (~1,000,000,000) we can synthetically cause a Worker exceeded CPU time limit. error.

Now, the issue is when we invoke the worker again. All subsequent invocations immediatelly fail with: The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response.. Based on the timings the worker code isn't being executed.

For more context, the dispatch-namespace is being invoked from a DurableObject:

[HTTP fetch]--->[DurableObject rpc]--->[DispatchNamespace fetch]

All of the errors get thrown when we call fetch on the stub returned from the dipatch namespace. After the initial invocation fails with Worker exceeded CPU time limit. the worker is essentially bricked. We cannot invoke it even with a low iteration count.

From my testing, if we re-deploy the dispatch-namespace worker, or rotate the DurableObject the requests are routed through - the error goes away.

To recap:

Invocation 1:
iterations = 100
  --> OK

Invocation 2:
iterations = 1,000,000,000. (after ~30 seconds)
  --> error: Worker exceeded CPU time limit.

Invocations 3,4,5,...:
iterations = 100 (thrown immediatelly)
 --> error: The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response.

Note that all code here (both the invoking worker and the dispatch-namespace one) run on Cloudflare hosted infrastructure, not locally.

Please provide any relevant error logs

No response

dmaretskyi avatar Dec 12 '25 17:12 dmaretskyi