question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 BUG: Startup script exceeded CPU time limit

See original GitHub issue

What version of Wrangler are you using?

2.1.15

What operating system are you using?

Mac

Describe the Bug

I’m trying to publish an update to an existing worker through wrangler and running into this error now. The worker is unbounded so it should have a much longer script startup and time limit than the other plan, but it doesn’t seem to make a difference.

I saw on the documentation that a worker’s size is limited to 1 MB after compression, and if thats the case then this should still work since the gzip size is ~930 KiB.

$ wrangler publish
 ⛅️ wrangler 2.1.15 
--------------------
▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.

Total Upload: 4816.91 KiB / gzip: 929.53 KiB

✘ [ERROR] A request to the Cloudflare API (*******) failed.

  Error: Script startup exceeded CPU time limit.
   [code: 10021]

  If you think this is a bug, please open an issue at:
  https://github.com/cloudflare/wrangler2/issues/new/choose

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

After trying with --minify enabled, the compressed size is even further decreased to ~700 KiB and still fails with the same error.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
callensmcommented, Nov 10, 2022

There are no additional scripts, just running via wrangler publish

Wrangler Toml

name = "****"
main = "src/index.ts"
compatibility_date = "2022-10-14"
node_compat = true
minify = true

[env.production]
name = "****"

Debug Log

$ wrangler publish
 ⛅️ wrangler 2.1.15 
--------------------
Retrieving cached values for userId from node_modules/.cache/wrangler
Metrics dispatcher: Dispatching disabled - would have sent {"type":"event","name":"deploy worker script","properties":{"usesTypeScript":true}}.
-- START CF API REQUEST: GET https://api.cloudflare.com/client/v4/accounts/******/workers/services/******
HEADERS: {
  "Authorization": "Bearer ******",
  "User-Agent": "wrangler/2.1.15"
}
INIT: {}
-- END CF API REQUEST
-- START CF API RESPONSE: OK 200
HEADERS: {}
RESPONSE: {
  "result": {
    "id": "******",
    "default_environment": {
      "environment": "production",
      "created_on": "2022-10-14T03:15:38.369656Z",
      "modified_on": "2022-11-10T15:40:15.24773Z",
      "script": {
        "created_on": "2022-10-14T03:15:38.369656Z",
        "modified_on": "2022-11-10T15:40:15.24773Z",
        "id": "******",
        "tag": "******",
        "tags": [],
        "version_id": "",
        "etag": "******",
        "handlers": [
          "router",
          "strict",
          "_tempPath",
          "path",
          "routes",
          "notFoundHandler",
          "errorHandler",
          "handleEvent",
          "fetch",
          "request",
          "get",
          "post",
          "put",
          "delete",
          "head",
          "options",
          "patch",
          "all"
        ],
        "last_deployed_from": "wrangler",
        "compatibility_date": "2022-10-14",
        "usage_model": "unbound"
      }
    },
    "created_on": "2022-10-14T03:15:38.369656Z",
    "modified_on": "2022-11-10T15:40:15.24773Z",
    "usage_model": "",
    "environments": [
      {
        "environment": "production",
        "created_on": "2022-10-14T03:15:38.369656Z",
        "modified_on": "2022-11-10T15:40:15.24773Z"
      }
    ]
  },
  "success": true,
  "errors": [],
  "messages": []
}

-- END CF API RESPONSE
▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.


-- START CF API REQUEST: PUT https://api.cloudflare.com/client/v4/accounts/******/workers/scripts/******?include_subdomain_availability=true&excludeScript=true
HEADERS: {
  "Authorization": "Bearer ******",
  "User-Agent": "wrangler/2.1.15"
}
INIT: {
  "method": "PUT",
  "body": {}
}
-- END CF API REQUEST
Total Upload: 2350.36 KiB / gzip: 717.17 KiB
-- START CF API RESPONSE: Bad Request 400
HEADERS: {}
RESPONSE: {
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10021,
      "message": "Error: Script startup exceeded CPU time limit.\n"
    }
  ],
  "messages": []
}

-- END CF API RESPONSE

✘ [ERROR] A request to the Cloudflare API (/accounts/******/workers/scripts/******) failed.

  Error: Script startup exceeded CPU time limit.
   [code: 10021]

  
  If you think this is a bug, please open an issue at:
  https://github.com/cloudflare/wrangler2/issues/new/choose


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
0reactions
JacobMGEvanscommented, Nov 14, 2022

it started after adding a certain dependency for a new feature, but even with the new dependency the compressed bundle size is within the limits.

This is for an unbound worker as well, so shouldn’t the time limit for startup scripts be much longer?

As @caass had mentioned it’s not a size issue.

The error you’re seeing is due to the script’s startup taking too long, not the script itself. If there’s heavy processing that happens before the fetch (or other event) handler is called, that can cause the script to time out. If you have any setup logic, it could be worth moving it inside the event handler and seeing if that fixes your issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceeds CPU time limit only on first few accesses #95
After a new deployment, I get a "CPU time limit exceeded" error only on the first few accesses. It may be related to...
Read more >
Exceeding CPU limit when running wrangler dev on paid ...
I was running into (expected) CPU limit issues on the free tier, so I've upgraded to the Paid tier, with a worker using...
Read more >
Apex CPU Time Limit Exceeded? Here's What to Do Next.
Seeing the error “Apex CPU time limit exceeded” means your transaction is taking too long and can't be completed. It's also likely a...
Read more >
Eliminating Apex CPU Time Limit Exceeded Errors in ...
The message indicates your transaction is taking too long and, therefore, has been shut down, with all completed and in-process tasks reverted.
Read more >
Limiting time and memory consumption of a program in Linux
Without further ado, the 14 kilobyte standalone Perl script that limits a program's CPU time and memory consumption on most Linux systems ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found