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

Is it possible to debug nodejs server with workers? #30197

Closed
gsbelarus opened this issue Oct 31, 2019 · 4 comments
Closed

Is it possible to debug nodejs server with workers? #30197

gsbelarus opened this issue Oct 31, 2019 · 4 comments

Comments

@gsbelarus
Copy link

Is it possible to debug workers? Every time I try, I get:

Starting inspector on 127.0.0.1:49344 failed: address already in use
Error: child process exit with code 12: connection problem

As soon as worker is created.

I use VS Code and launch.json looks like:

    {
      "type": "node",
      "request": "launch",
      "name": "Debug gdmn-back",
      "cwd": "${workspaceRoot}/src/gdmn-back",
      "program": "${workspaceRoot}/src/gdmn-back/src/index.ts",
      "outFiles": [
        "${workspaceRoot}/src/gdmn-back/dist/src/**/*.js"
      ],
      "console": "externalTerminal",
      "internalConsoleOptions": "openOnSessionStart",
      "autoAttachChildProcesses": true
    },

I think, if it is NOT POSSIBLE at all, it should be printed with bold letters at the start of corresponding chapter of Nodejs docs. So, there will be no need to spend days searching internet for a solution which doesn't exist.

If there is a way, then it would be good to add it to official docs. As both nodejs and vscode web sites don't say a word about the topic.

I love Nodejs, but inability to debug workers code makes me mad ((

@addaleax
Copy link
Member

@gsbelarus Are you talking about worker_threads workers or cluster workers?

If it’s worker_threads workers, Chrome DevTools doesn’t support them yet but e.g. https://github.com/GoogleChromeLabs/ndb/ and some IDEs do.

If it’s cluster workers, yes, that is possible. If necessary, you can manually specify a port using inspectPort: https://nodejs.org/api/cluster.html#cluster_cluster_settings

@gsbelarus
Copy link
Author

We use worker_threads. I will evaluate ndb. Thanks for the link!

@gsbelarus
Copy link
Author

Seems it works for me:

  1. open command prompt with admin rights
  2. yarn global add ndb
  3. cd to project folder
  4. yarn rebuild
  5. ndb node ./dist/src/index.js (path will depend on project!)
  6. if you need to set break point before project starts open ndb with command ndb ., browse to sources and put break point, then follow Consistent sync and async function names #5.

lundibundi added a commit to lundibundi/node that referenced this issue Nov 22, 2019
@danbev danbev closed this as completed in 84a95b8 Nov 25, 2019
addaleax pushed a commit that referenced this issue Nov 30, 2019
PR-URL: #30594
Fixes: #30197
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
targos pushed a commit that referenced this issue Dec 1, 2019
PR-URL: #30594
Fixes: #30197
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
MylesBorins pushed a commit that referenced this issue Dec 17, 2019
PR-URL: #30594
Fixes: #30197
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@danieltroger
Copy link

danieltroger commented Nov 7, 2023

Is there any way of doing this now that ndb is dead/deprecated? ndb crashes for me and I really want a debugger in worker_threads

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 a pull request may close this issue.

3 participants