Skip to content

Restarting Debugger Failing to Kill Nodemon #56756

Closed

Description

@p-rk
  • VSCode Version: 1.26.1
  • OS Version: MAC OS 10.12.6

Steps to Reproduce:

  1. Start Debugger fn + F5
  2. Restart debugger from the debugger panel. It first crashes the app and then tries to restart but it gets timeout saying this

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:29557).

When i see in the integrated terminal it show me up

[nodemon] app crashed - waiting for file changes before starting...

My launch configuration

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch via Nodemon",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "nodemon",
      "program": "${workspaceFolder}/api/api.js",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "env":{"NODE_ENV":"development"},
      "timeout": 10000
    },
  ]
}

Does this issue occur when all extensions are disabled?: Yes

Activity

  1. vscodebot commented on Aug 19, 2018

    @vscodebot

    (Experimental duplicate detection)
    Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

  2. added
    debug
    on Aug 20, 2018
  3. added
    bug
    on Aug 20, 2018
  4. markm77 commented on Jan 3, 2019

    @markm77

    Please note also that if you quit VS Code after launching nodemon-hosted processes and don't stop them all manually in each process terminal with Cntrl-C you will find orphaned Node processes in Activity Monitor still running and consuming CPU after VS Code has stopped. These can of course be manually force-quit in Activity Monitor. I have requested an update for tasks to allow automatic process clean-up via a task (#65986). But "proper" support for nodemon such that Debug Stop and Debug Restart kill all relevant processes is the best solution assuming this is possible. For reference, I use compound of launch configs that look like below.

            {
                "type": "node",
                "request": "launch",
                "name": "Api",
                "runtimeExecutable": "nodemon",
                "cwd": "${workspaceFolder}/built",
                "program": "${workspaceFolder}/built/app.js",
                "restart": true,
                "env": {
                    "NODE_ENV": "development",
                    "DOMAIN": "xxx",
                    "FORCE_COLOR": "10"
                },
                "port":9300,
                "runtimeArgs": [
                    "--inspect-brk=9300"
                ],
                //"outputCapture": "std",
                "console": "integratedTerminal",
                "internalConsoleOptions": "neverOpen"
            },
    
  5. thomas-darling commented on Feb 12, 2019

    @thomas-darling

    This really needs to be fixed, asap.

    In my case, if I forget to manually kill the orphaned nodemon processes, they will eventually get stuck in a loop and start consuming 100% CPU. It's a major problem, and one that makes development using nodemon completely impractical.

    Please find a way to automatically and reliably kill nodemon when debugging is stopped.

  6. thomas-darling commented on Feb 12, 2019

    @thomas-darling

    Wait a second - it actually looks like I have some success with the --exitcrash argument mentioned in #40430 (comment).

    When that argument is specified, it actually looks like the nodemon process is killed when debugging is stopped or restarted 🎉

    If that's really all it takes, the documentation here should probably be updated to mention that, instead of the current tip, which suggests that we must manually kill the orphaned nodemon processes.

  7. markm77 commented on May 22, 2019

    @markm77

    Great posts Thomas Darling (@thomas-darling). --exitcrash stops abandoned node processes for me.

    However the next problem I have then is that 'Restart Debugging' generally opens a new integrated terminal (only sometimes reuses an existing terminal) and since I run a compound debug config (multiple processes) I end up with multiple abandoned terminals with last line showing "[nodemon] app crashed". This problem would be solved I believe by the ability to specify the presentation property for a launch config. (See #68123 (comment)). This would allow to specify presentation.panel as dedicated or new to choose if an existing terminal should be reused on 'Restart Debugging'. This issue is also relevant when using external terminals.

    (As a side note, right now for me I can't use nodemon and integrated terminals at all (!) due to #71850 😟. But I hope that will get resolved not too long away.)

  8. rajatkantinandi commented on Jan 6, 2020

    @rajatkantinandi

    I have a different issue even while nodemon if I save a file the server restarts but after that 2 processes with node --inspect-brk=port keep running with high CPU usage.
    They have a port that doesn't match with the debugger port shown in the terminal.
    And even if I terminate those processes nodemon keeps running, indicating that those processes have no relation to the currently running server with nodemon.
    Even if I quit VSCode those 2 processes keeps running. And there are only 2 processes never more than 2 or less than 2.
    Attaching screenshots below:

    Screenshot 2020-01-06 at 12 37 25 PM

    You can see in the screenshot there are 3 node processes, the bottom one is the actual process which is running the server, which has quite low CPU usage.
    The top 2 processes are using too much CPU.

    Here is the screenshot of the integrated terminal showing the debugger port:

    Screenshot 2020-01-06 at 12 37 58 PM

    Launch config:

    {
          "name": "Launch Nodemon in Debug Mode",
          "type": "node",
          "request": "launch",
          "runtimeExecutable": "npx",
          "program": "${workspaceFolder}/build/app.js",
          "cwd": "${workspaceRoot}",
          "preLaunchTask": null,
          "runtimeArgs": [
            "nodemon",
            "--nolazy",
            "--exitcrash"
          ],
          "env": {
            "NODE_ENV": "development",
            "NEW_RELIC_ENABLED": "false",
          },
          "console": "integratedTerminal",
          "outFiles": [
            "${workspaceRoot}/**/*.js"
          ],
          "sourceMaps": true,
          "protocol": "inspector",
          "restart": true
    }
  9. connor4312 commented on Nov 5, 2020

    @connor4312
    Member

    We since have a new debugger that handles child processes and trees like Nodemon in a more reliable way. Please let us know if you're still running into problems, and if so open an issue on that repo.

  10. locked and limited conversation to collaborators on Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugdebug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions