remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.13k stars 1.72k forks source link

nodemon called as a subprocess within a subprocess breaks stdin after SIGINT #2154

Closed rtpg closed 5 months ago

rtpg commented 6 months ago

I have the following environment:

// package.json
{
  "dependencies": {
    "nodemon": "^3.0.2"
  },
  "scripts": {
    "dev1": "./call_nodemon.js dev_busted",
    "dev2": "./call_nodemon.js dev_fine",
    "dev_busted": "(nodemon --exec 'echo hi') || echo 'no'",
    "dev_fine": "(nodemon --exec 'echo hi')"
  }
}
//call_nodemon.js
#!/usr/bin/env node
const cp = require("child_process");
cp.spawn("npm", ["run", process.argv[2]], {
  stdio :[process.stdin, "pipe", process.stderr]
})

If I call npm run dev1, then SIGINT with Ctrl-C, my shell ends up stuck in (I believe) raw mode (maybe echo-only mode, having trouble telling). I believe this is happening during teardown of some child processes due to my shell sometimes working for a second before breaking (i.e. the prompt prints, and I have a half second window where the up or down arrow properly lets me search history, then I get the telltale ^[0A^[0B `stuff)

If I run npm run dev2 this does not happen (the difference being the extra echo call or no)

If I run npm run dev_busted directly, the issue does not happen.

If, I comment out process.once('SIGINT' , () => bus.emit('quit', 130) in lib/monitor/run.js, the issue no longer happens (though there are obviously probably consequences to that on nodemon overall)

If I replace that line with process.once('SIGINT', () => {}), the issue does happen. I have reported an issue upstream to nodejs that seems to indicate something weird going on in that front.

(some context: the original place where I had the issue was an npm-run-all script calling into nodemon. I stripped everything down to the cp.spawn call I have in call_nodemon.js, but that's how I ended up with this setup)

Versions

Expected behaviour

After I terminate nodemon with SIGINT, my shell should recover

rtpg commented 6 months ago

sample execution

rtpg@HOSTNAME ‹ main ●● › : ~/proj/break
[1] % npm run dev1      

> dev1
> ./call_nodemon.js dev_busted

^C

rtpg@HOSTNAME ‹ main ●● › : ~/proj/break
[130] % npm ERR! path /home/rtpg/proj/break
npm ERR! command failed
npm ERR! signal SIGPIPE
npm ERR! command /usr/bin/bash -c (nodemon --exec 'echo hi') || echo 'no'

npm ERR! A complete log of this run can be found in: /home/rtpg/.npm/_logs/2023-12-21T05_31_20_117Z-debug-0.log
^[OA^[OB^[OA^[OB^[OA

session example, notice how the npm error shows up after my prompt appears, and then a bunch of "raw" up and down arrow keypressees (SIGINT'ing again with Ctrl-C does fix my shell though)

github-actions[bot] commented 6 months ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

rtpg commented 6 months ago

I believe this to still be an issue, though I personally have a workaround of passing in /dev/null as stdin to nodemon as a workaround

github-actions[bot] commented 6 months ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

github-actions[bot] commented 5 months ago

Automatically closing this issue due to lack of activity