Skip to content

Conversation

@Alanoll
Copy link
Contributor

@Alanoll Alanoll commented Dec 27, 2025

#702 fixed the fact that the debugger never attached to projects using the project style configuration, but I found in my larger repo's that a potential deadlock could occur waiting for the debugger to attach.

Scenario:
The RPC event onBrowserDebug is sent as soon as VSCode completes it's promise to attach to the browser in the then. There's a timing issue if the browser hasn't yet executed the setupFile from the extension that triggers the await for the event.

So:

  1. Start Debug
  2. Extension launches debug session for VSCode to attach to the browser
  3. Vitest spins up the test project and initializes
  4. VSCode completes attaching and triggers onBrowserDebug event
  5. Browser loads the setupFile browserSetupFile.ts that await for the onBrowserEvent via the __vscode_waitForDebugger command created here

Because the event fired before the setupfile started to listen, the debug session deadlocks here waiting for the signal.

This PR starts listening to the event before adding the setupFile to the project collection, and stores the state in a private variable. The Command now checks this variable first to see if it's already attached (and immediately returns) or subscribes to the event again like it was doing before to resolve the promise.

@Alanoll
Copy link
Contributor Author

Alanoll commented Dec 27, 2025

@sheremet-va This (if approved) I think might need to be in the same release as #702

// Listen for debugger attachment events as soon as possible to prevent a deadlock
//
ExtensionWorker.emitter.on('onBrowserDebug', (fullfilled) => {
this.debuggerAttached = fullfilled
Copy link
Member

Choose a reason for hiding this comment

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

I would expect __vscode_waitForDebugger to throw an error if fullfilled is false. This PR will still wait indefinitely. Maybe have debuggerAttached as undefined by default

Copy link
Contributor Author

@Alanoll Alanoll Dec 29, 2025

Choose a reason for hiding this comment

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

Give it a look now. I've added the undefined to checks so it'll treat a false value as "VSCode has already failed to attach"

I followed the already existing pattern to reject the promise with an error.

@Alanoll Alanoll requested a review from sheremet-va December 29, 2025 16:42
@sheremet-va sheremet-va merged commit dd77eb0 into vitest-dev:main Jan 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants