Skip to content

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

Description

@gsbelarus

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 ((

Activity

  1. addaleax commented on Oct 31, 2019

    @addaleax
    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

  2. gsbelarus commented on Oct 31, 2019

    @gsbelarus
    Author

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

  3. gsbelarus commented on Oct 31, 2019

    @gsbelarus
    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.
  4. danieltroger commented on Nov 7, 2023

    @danieltroger

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions