Skip to content

Fix execution freezing on debugger statements when DevTools is not attached#12835

Merged
dario-piotrowicz merged 2 commits intomainfrom
dario/7956/no-debugger-enable-message
Mar 16, 2026
Merged

Fix execution freezing on debugger statements when DevTools is not attached#12835
dario-piotrowicz merged 2 commits intomainfrom
dario/7956/no-debugger-enable-message

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Mar 10, 2026

Fixes #7956

Previously, wrangler always tried to connect to an inspector debugger, even when DevTools wasn't open. This caused scripts to freeze on debugger statements. Now the connection is only made when DevTools is actually attached.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
      • pull down the issue's minimal reproduction
      • run npm i and npm start, try fetching/visiting the worker's url and notice its execution being blocked
      • install this PR's prerelease (npm i https://pkg.pr.new/wrangler@12835)
      • try npm start again and see that the execution is no longer blocked
      • press the d hotkey and fetch from the worker again, see that debugging still works as expected
      • try to run npm start in a vscode debugger terminal and see that debugging still works as expected
      • run again the command normally and try to debug via chome's chrome://inspect page, see that debugging still works as expected
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 10, 2026

🦋 Changeset detected

Latest commit: 50944aa

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Mar 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

✅ All changesets look good

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 10, 2026

Now I have a clear picture of the change. Let me analyze the logic:

  1. Before this PR: When the runtime WebSocket opens (handleRuntimeWebSocketOpen), three messages were sent: Runtime.enable, Debugger.enable, and Network.enable. Sending Debugger.enable causes the runtime to activate its debugger, which means debugger statements will pause execution — even if no DevTools is attached.

  2. After this PR: Debugger.enable is removed from the initial connection. DevTools itself sends Debugger.enable when it connects (as noted in the comment at line 568). This means the debugger is only active when DevTools is actually attached.

  3. The Debugger.disable at line 570-573: When a new DevTools WebSocket connects, it sends Debugger.disable first, then DevTools sends Debugger.enable to re-initialize. This flow remains intact and correct.

  4. The Debugger.scriptParsed events buffering: The tryDrainRuntimeMessageBuffer at line 266 buffers messages including Debugger.scriptParsed events for when DevTools connects. Since Debugger.enable won't be sent until DevTools connects, there won't be Debugger.scriptParsed events to buffer before DevTools — but that's fine because once DevTools sends Debugger.enable, these events will come fresh.

The change is clean and correct. The changeset is properly formatted. The only thing removed is the premature Debugger.enable that was causing the freeze, and the existing mechanism for DevTools to send its own Debugger.enable on connect is already in place.

LGTM

github run

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 10, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12835

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12835

miniflare

npm i https://pkg.pr.new/miniflare@12835

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12835

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12835

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12835

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12835

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12835

wrangler

npm i https://pkg.pr.new/wrangler@12835

commit: 50944aa

@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review March 10, 2026 16:50
@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner March 10, 2026 16:50
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 10, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

@dario-piotrowicz dario-piotrowicz force-pushed the dario/7956/no-debugger-enable-message branch 2 times, most recently from 490609a to a9d451f Compare March 11, 2026 11:43
@dario-piotrowicz dario-piotrowicz force-pushed the dario/7956/no-debugger-enable-message branch from a9d451f to e0f2fa9 Compare March 12, 2026 16:47
@petebacondarwin petebacondarwin self-requested a review March 13, 2026 13:31
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to pull this down to test but LGTM.
One question... should we disable when the devtools closes? Or does it do that for us?

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does fix the direct issue of debugger statements blocking execution when the devtools has not yet started. So approving this PR as an improvement.

But there is an additional problem... if you open up the devtools it will enable the debugger as desired. But then if you close the devtools the debugger is still enabled and will resort to blocking the request again.

So as a follow up we should investigate how to solve that.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 13, 2026
@dario-piotrowicz
Copy link
Copy Markdown
Member Author

Thanks a lot @petebacondarwin 😄

Yeah I didn't consider the devtools closing situation! 😓 I'll quickly look into it now 🙏

@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@dario-piotrowicz
Copy link
Copy Markdown
Member Author

@petebacondarwin 50944aa should address the client closing concern 😄 (again, thanks a lot for surfacing the issue! 🙏)

Please have another look 🙂🙏

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I didn't try the disable bit manually but it looks solid. Thanks Dario.

@dario-piotrowicz dario-piotrowicz merged commit c600ce0 into main Mar 16, 2026
49 of 51 checks passed
@dario-piotrowicz dario-piotrowicz deleted the dario/7956/no-debugger-enable-message branch March 16, 2026 12:10
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 BUG: execution freezes on debugger statements when no inspector is open

3 participants