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.21k stars 1.72k forks source link

Executing execSync in response to pressing ctrl+c inside nodemon fails due to whitespace. #2103

Closed grainstackdev closed 1 year ago

grainstackdev commented 1 year ago

Expected behaviour

execSync should have the same behavior independent of whether or not it is running in nodemon.

Actual behaviour

When running inside nodemon, there is a consistent way of causing execSync to fail

Steps to reproduce

Please check out this repo which I have made to reproduce this bug: https://github.com/grainstackdev/bug-execSync

To reproduce:

  1. git clone
  2. yarn
  3. npm start
  4. ctrl+c
  5. You should see the program stop as expected with no error message, so npm -v worked.
  6. Uncomment stopFails() and comment stopWorks(). These are the lines: https://github.com/grainstackdev/bug-execSync/blob/master/src/backend/src/localServer.js#L29-L30
  7. npm start
  8. ctrl+c
  9. You should see the program stop, but with an error message this time, saying "Error: Command failed: npm -v".

And here is a clip demonstrating the above steps: 2023-03-08 03-57-46 1678277500537

Some other observations:


If applicable, please append the --dump flag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.

remy commented 1 year ago

I think this is a node bug. I just tried with node@16.17.1 and it replicates.

I then switch to node@18 (v18.8.0) and it doesn't fail.

My guess is that it's related to how sub-processes are spawned (and forked). The problem is - looking at the docs and the change log around execSync there's nothing suggesting there's been a change.

Can you try with current LTS node (18) and let me know how get on (it's definitely a head scratcher).

grainstackdev commented 1 year ago

It doesn't work for me on node 18 (v18.15.0). When I try, I get the same command failed error. However, when I first installed node 18 via nvm, and then tried to replicate the bug the first time, it almost worked. I didn't get the error that time, however, the program did not stop, returning me to a ready CLI prompt, as expected. But then I tried running it again, and then I started getting the same command failed error again.

Also, on node 18, sometimes when running const command = 'npm -v\n '. I get the same hanging issue I got the first time I tried running it on 18. Pressing ctrl+c will make it hang, not returning to the ready CLI, but it looks like it runs execSync without error.

It seems like this hanging behavior is intermittent and I can't get it to reproduce consistently. On node 16, I never get the hanging.

If anyone else is getting this issue, I recommend staying on node 16 rather than 18 in order to avoid the intermittent hanging issue.

It's very strange.

github-actions[bot] commented 1 year 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 1 year ago

Automatically closing this issue due to lack of activity