Skip to content

Debugger shows incorrect thread state if "continued" arrives too soon after a "stopped" (or "started"?) #238591

Closed

Description

@DanTup

I had a bug raised against Dart where the debugger shows threads as "paused on entry" when they should not be. The DAP traffic looks good:

// Start
[5:17:21 PM] [DAP] [Info] <== {"seq":21,"type":"event","body":{"reason":"started","threadId":3},"event":"thread"}
// Pause
[5:17:21 PM] [DAP] [Info] <== {"seq":43,"type":"event","body":{"allThreadsStopped":false,"reason":"entry","threadId":3},"event":"stopped"}
// Resume
[5:17:21 PM] [DAP] [Info] <== {"seq":78,"type":"event","body":{"allThreadsContinued":false,"threadId":3},"event":"continued"}

Yet the UI shows the thread as paused. I was able to reproduce this in MockDebug. It seems to only occur when the events occur close together (if I add delays, it doesn't seem to happen):

// Start additional threads, pause on entry, continue.
for (var i = 2; i < 5; i++) {
	this._threads.push(new Thread(i, `Thread ${i}`));
	this.sendEvent(new ThreadEvent('started', i));
	this.sendEvent(new OutputEvent(`Thread ${i} started\n`));
	this.sendEvent(new StoppedEvent('entry', i));
	this.sendEvent(new OutputEvent(`Thread ${i} stopped on entry\n`));
	// await this.delay(1); // Uncomment this to fix it
	this.sendEvent(new ContinuedEvent(i, false));
	this.sendEvent(new OutputEvent(`Thread ${i} continued\n`));
}

Image

Full repro is here:

https://github.com/DanTup/vscode-mock-debug/tree/repro-dart-code-5397 / DanTup/vscode-mock-debug@04f4764

This felt a bit like microsoft/debug-adapter-protocol#513 to me, but that actually turned out to be caused by allThreadsStopped defaulting to true. I don't believe that's the case here because in the real project where this happens (Dart debugger), we set both allThreadsStopped and allThreadsContinued to false (though I haven't set allThreadsContinued in the MockDebug example because it doesn't seem to be available in the constructor... I don't believe that's the issue though as allThreadsContinued seems to default to false and the delay shouldn't fix the issue in that case).

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    debugDebug viewlet, configurations, breakpoints, adapter issues
    on Feb 4, 2025
  2. vasilich6107 commented on Jun 3, 2025

    @vasilich6107
  3. Rodsevich commented on Jun 30, 2025

    @Rodsevich
  4. yohanangulo commented on Jul 20, 2025

    @yohanangulo
  5. vasilich6107 commented on Jul 20, 2025

    @vasilich6107
  6. ChuckPG commented on Jul 30, 2025

    @ChuckPG
  7. roblourens commented on Jul 31, 2025

    @roblourens
    Member

    I think this is because we have not done fetchThreads yet when the 'continue' event comes in. Connor Peet (@connor4312) this might be from #197397 (or maybe it predates that, not sure)

    Probably we need to force waiting on a fetchThreads when we get an event for a thread that we don't know about yet.

  8. Mercutio1243 commented on Aug 1, 2025

    @Mercutio1243

    Is there an update on this?

    I did not face this issue last year, only now when setting up VS Code on my new laptop.

    Is there a workaround such as downgrading VS Code to earlier versions to avoid this?

  9. luishugoooo commented on Aug 10, 2025

    @luishugoooo
  10. diegocontini commented on Aug 16, 2025

    @diegocontini
  11. sprite2005 commented on Aug 25, 2025

    @sprite2005
  12. DanTup commented on Aug 26, 2025

    @DanTup
    ContributorAuthor

    roblourens Connor Peet (@connor4312) I'm unfamiliar with this code but there's a Copilot button in the sidebar so I figured I'd see what it did given the comments above.

    It did this:

    DanTup@8dce956

    The fix seems to match your suggestion, although the test seems a bit of a mess. If this looks like the right approach, I could try to write a better test (and verify the fix against my repros above).

  13. connor4312 commented on Sep 8, 2025

    @connor4312
    Member

    Thanks for the nice repro 🙏

  14. added a commit that references this issue on Sep 8, 2025
    e80990b
  15. added a commit that references this issue on Sep 9, 2025
    6068add
  16. added
    unreleasedPatch has not yet been released in VS Code Insiders
    insiders-releasedPatch has been released in VS Code Insiders
    and removed
    unreleasedPatch has not yet been released in VS Code Insiders
    on Sep 9, 2025
  17. locked and limited conversation to collaborators on Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugdebugDebug viewlet, configurations, breakpoints, adapter issuesinsiders-releasedPatch has been released in VS Code InsidersverifiedVerification succeeded

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions