Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of exited threads in debugger #12112

Closed
EvilBeaver opened this issue Jan 26, 2023 · 4 comments · Fixed by #12113
Closed

Incorrect handling of exited threads in debugger #12112

EvilBeaver opened this issue Jan 26, 2023 · 4 comments · Fixed by #12113
Labels
debug issues that related to debug functionality

Comments

@EvilBeaver
Copy link
Contributor

Bug Description:

If debug thread is exited it does not removed from the threads panel till next stop and Threads request to debug adapter.
This leads to incorrect display and sometimes to broken debugger behavior.

Steps to Reproduce:

  1. launch debugger of some language with debug adapter
  2. See that no threads shown, only session
  3. stop at breakpoint
  4. continue to thread exit
  5. see that threads panel still shows thread in a Running state

Expected: no running threads shown, showing Session only, as it was at very beginning.
Things are getting worse if there's multiple stopped threads and they all continued to the exit.

threads-3

On the picture Thread 24 already exited and not running.
Expected that threads panel looks like this when no debuggable threads available

session

Additional Information

It seems it should be fixed here https://github.com/eclipse-theia/theia/blob/master/packages/debug/src/browser/debug-session.tsx#L912, need to remove thread from this._threads on thread exited.

  • Operating System: any
  • Theia Version: cloned from master
EvilBeaver pushed a commit to EvilBeaver/theia that referenced this issue Jan 26, 2023
@vince-fugnitto vince-fugnitto added the debug issues that related to debug functionality label Jan 26, 2023
@vince-fugnitto
Copy link
Member

@EvilBeaver do you happen to have additional details to consistently reproduce the bug?
I've tried with node debugging (ex: run mocha tests) and the threads view is correctly cleared on exit.

@EvilBeaver
Copy link
Contributor Author

EvilBeaver commented Feb 1, 2023

To reproduce this, you'll need to have no threads debugged (all exited), but debug session still active. I suppose it's hard to achieve in node.js, cause it's usually single threaded and all threads exit also means session exit.

@alvsan09
Copy link
Contributor

alvsan09 commented May 4, 2023

I have tried to reproduce this issue using multiple threads spawned by the following 'javascript' program,
you can launch this program multiple times and see how the threads get cleared as expected.

the following recording shows the execution:
https://user-images.githubusercontent.com/76971376/236262803-4790db9b-7ec3-4ea7-a55c-d242033019b9.mp4

Any additional ideas on how to reproduce this issue are very welcome !

const { spawn } = require('child_process');

const numberOfThreads = 5;
const threadDuration = 5000;
const createInterval = 1000;

function spawnThread() {
    const child = spawn('node', ['-e', `setTimeout(() => {}, ${threadDuration});`]);
    child.on('spawn', () => {
        console.log(`Thread ${child.pid} created`);
    });
    child.on('close', () => {
        console.log(`Thread ${child.pid} exited`);
    });
}

let threadsSpawned = 0;
const intervalId = setInterval(() => {
    spawnThread();
    threadsSpawned++;
    if (threadsSpawned === numberOfThreads) {
        clearInterval(intervalId);
    }
}, createInterval);

@EvilBeaver
Copy link
Contributor Author

@alvsan09 I don't know how to reproduce this in node debugger. I'm writing a debug adapter for another language. Here's a code line with a problem: https://github.com/eclipse-theia/theia/blob/master/packages/debug/src/browser/debug-session.tsx#L912 nobody deletes a thread from _threads collection, thus last exited thread does not get removed from threads panel.

In your example you need to have spawning.js exited, but session still active. This can't be achieved in current node.js debugger

EvilBeaver pushed a commit to EvilBeaver/theia that referenced this issue May 18, 2023
EvilBeaver pushed a commit to EvilBeaver/theia that referenced this issue May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debug issues that related to debug functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants