Worker failing mysteriously with exceeded CPU time limit.

I'm trying to run this minimal worker:

// Worker
export default {
    async fetch(request: Request) {
        let stopTime = Date.now() + 1; //1ms
        let curTime = Date.now()
        while(curTime < stopTime) {
            curTime =  Date.now()
        }
        return new Response();
    }
};


When this worker is deployed with:
npx wrangler dev --remote=false:
  • Calls to the worker SUCCEED after ~1ms
npx wrangler dev --remote=true:
  • Calls to the worker hang for 39 seconds then FAIL with exceeded CPU time limit.
npx wrangler deploy:
  • Calls to the worker hang for 39 seconds then FAIL with exceeded CPU time limit.
------

Is this intended behavior? What's the reason for this occurring?
Was this page helpful?