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

Unable to debug worker threads #6

Open
jZhangTk opened this issue Aug 21, 2022 · 3 comments
Open

Unable to debug worker threads #6

jZhangTk opened this issue Aug 21, 2022 · 3 comments

Comments

@jZhangTk
Copy link

I'm trying to debug with worker threads. When it hits a breakpoint (DapStopped sign shows up), I can't continue, step over, inspect a variable, etc. It acts as it doesn't know it hit a breakpoint. When I do :lua require'dap'.continue() to continue, it gives me

Session active, but not stopped at breakpoint

And when I do :lua require'dap.ui.widgets'.hover() to inspect a variable, it gives me

Cannot evaluate "foo"!

Below is my config for javascript. It works perfectly without worker threads. And it also works in VS Code with worker threads (with "type": "node").

{
  type = 'pwa-node',
  request = 'launch',
  name = 'Debug',
  program = '${file}',
  cwd = '${fileDirname}',
  sourceMaps = true,
  skipFiles = { '<node_internals>/**' },
  outputCapture = 'std',
  resolveSourceMapLocations = {
    '**',
    '!**/node_modules/**',
  },
},

Is this a bug or misconfiguration?

@mxsdev
Copy link
Owner

mxsdev commented Sep 10, 2022

Hi, sorry for the late reply!

Can you send an MRE? I just tested a simple node.js project with worker threads using your configuration, and I was unable to replicate the issue.

@jZhangTk
Copy link
Author

@mxsdev I'm sorry, what do you mean by MRE?

As I did a quick test with simple worker threads, it indeed worked. There must be something special I'm doing in my project caused the behaviour. Let me dig a little further and get back to you.

@jZhangTk
Copy link
Author

Actually, it is not worker_threads but threads causing the issue.

Steps to reproduce:

  1. put the below files in the same folder
  2. npm i threads in that folder
  3. set a breakpoint at any line between new Worker() (excluded) and Thread.terminate() (included), or inside of the work() function
  4. debug index.js

Once it hits the breakpoint, you should see the behaviour described earlier (VS Code works just fine though). In addition, once the thread is terminated (e.g. console.log('done')), everything is back to normal. It seems like something is acting up with the threads created by new Worker().

// index.js
const { spawn, Thread, Worker } = require('threads');
const main = async function () {
    const worker = new Worker('./worker.js');
    const instance = await spawn(worker);
    await instance.work();
    await Thread.terminate(instance);
    console.log('done');
};
main();
// worker.js
const { expose } = require('threads');
expose({
    work() {
        console.log('hello world');
    },
});

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

No branches or pull requests

2 participants