Repository navigation
Closed as not planned
Labels
child_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.
Description
Version
16.*
Platform
linux
Linux f092196b2008 5.10.104-linuxkit #1 SMP Thu Mar 17 17:08:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
What steps will reproduce the bug?
I've created a demo using docker so you can easily swap node versions and see the bug.
That being said, I'm sharing the tarball as bas64 because I wasn't sure if you'd like to download tarballs...that being said you may also not want to decode b64 🤷♂️
download here if you'd like: poc
or run the following:
base64 -d <<< H4sIACurxWIAA+1YbWvbMBDOZ/+KqzfqZCSyZcsxBLoLjpJp+fRKchuVA7HcQLfB912y9ZxSdkuAJi4Xey5PvE9cDAmJGiAX/3UGo2ZKMJcTiW8YGH8gJ90G40e6F+sY9W+ECB7OGNJ3Ek7+SxFYlJFjHX5x06wyr/nuzL/BHvdBjhVTOY+Xnn+32zZQ5baw1BMjCIc75gpjynudiZhOqa5acQ8Oqc56EMCnQLeSidAS7M8M9piPPcyavwlkP1Bp3LEElpVDMmHLiEP8B/7S/4T38eS/x7xSM3/TeDToP8NFOd7kvQiYVPD+N4ffP2wNwCbZ4Vh7PYPjgFJyhsf948Gxwf9vf0jOAGtE2YbTJbG9Bf6IUw4rVXg5QHZKpFnUx7PEiqqKQYfUf8RQhx9/+O6/tsIkL0kcHUx1um/G9zKv9dV+o+xV+v/JhDxVBRwLbLwMj28SqM57EBOf85YTptWNJFV31mW84gKYbUMQ3nzhKKEj5vWofoNS8cIIdm3GqFppdnUap9YTI4cJonVtpCdnY9l2+lc0HzIBbVO2zJmETPek24TmrPCakPBppTPih6WG/jOm7fuhtMBVCl6RWW45963/wU6NRX/B/AY/cdBIPnvup5b6/8mUOY/C6PzcEzlLcDTp4+xTv89n9zov0PU/e/X+r8ZXBsga/lwSs0emPIomG1lkDItGE+VDSMHOaU1piLKWVYsekrjNGT62+odoK2lo5AdKoA0ZDld3AfKmUYTDtYXmiQcRjmfgkgozaS437htWbC9rV8mgGzdrQaXg811gHN6dcnzWEU4OdWWcFZMeH4zsYRFNBV6XXuHu6Yxr++MP6Dk/3J/q4mx9v3vBff03wscXPN/E7hbYqljICs6SbtLVdLR4qgsyZrN1s77O66fOY9hynNVAFqtti7ZuurTAtuGEBJeyLqwpty/jnvvfykGTx/j8e9/3/fk/e8iVM2EbuOV879GjRqvF78BY21wXQAgAAA= > out.tar.gzthen tar -zxf out.tar.gz and you'll see the following files:
Dockerfile build-n-run.sh index.js node_modules pkgyou can run the build-n-run.sh that I've created (which is a silly 2liner), or build and run it yourself
Steps to Reproduce
- Run something like:
const {spawnSync} = require('child_process')
console.log('Spawning...')
spawnSync('npm',['install','./pkg','--verbose'], {stdio:'inherit', timeout:1000*3})
console.log('spawner bye')and make the package preinstall script for pkg to hang (via long setTimeout that will make it busy)
3. Expect ETIMEOUT, but get nothing
Metadata
Metadata
Assignees
Labels
child_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.
Activity
mscdex commentedon Jul 6, 2022
Using 'sleep 10' as the command works for me.
Are you expecting a thrown exception? You need to be checking the return value of
spawnSync()(specifically.error), as that is where you'll find theETIMEDOUTerror.aviadhahami commentedon Jul 6, 2022
I'd expect it to terminate at first, then check the status code;
wdym by
sleep 10? did u try my poc?mscdex commentedon Jul 6, 2022
When I tested,
spawnSync()returned after 3 seconds (due toETIMEDOUT). From there, you just check the various properties from the returned object.No, 'sleep 10' should be equivalent.
aviadhahami commentedon Jul 6, 2022
interesting; I'm checking this in the above env
aviadhahami commentedon Jul 6, 2022
you are not wrong - I can reproduce it as well;
That being said - my POC still works. I'll try to reduce it to the bare minimum, I have a feeling it has to do with multiple children or so.
This is
ps auxfrom the hanging container (with poc):Minus the last 2 procs - the rest are the hanged
====
Update:
I'm unable to repro this using simple spawns, but yes every time using the npm install :\
wa-Nadoo commentedon Jul 6, 2022
Please try to add killSignal: 'SIGKILL' option to spawn. By default spawn sends SIGTERM signal to child process that not enough for some programs.
aviadhahami commentedon Jul 7, 2022
@wa-Nadoo this doesn't work either;
tho regardless of the signal itself -- I would expect it to terminate;
This works on node 14, but doesn't on 16;
aviadhahami commentedon Jul 7, 2022
Checked, it reproduces on these node versions: 16,17,18
[-]node16 doesn't respect spawn timeout and hangs[/-][+]node {16|17|18} doesn't respect spawn timeout and hangs[/+][-]node {16|17|18} doesn't respect spawn timeout and hangs[/-][+]node {16,17,18} doesn't respect spawn timeout and hangs[/+]lirantal commentedon Jul 7, 2022
@aviadhahami can you check if you're also using different npm versions along with those 16,17,18 runtime versions? I suspect that it's the npm executable specifically that is indeed not respecting/forwarding signals correctly to child processes that it spawns.
aviadhahami commentedon Jul 7, 2022
For the supplied PoC, these are the versions:
node:16-slim-[email protected]node:17-slim-[email protected]node:18-slim-[email protected]lirantal commentedon Jul 7, 2022
Ok, so pretty close version ranges so I assume no big changes there, although worth looking into the changelog and see if anything obvious comes up in the diff.
benjamingr commentedon Jul 8, 2022
Does the issue reproduce when you manually when you spawn
npmin these versions in a terminal andkillit from another terminal? (find it withpsand send it the same signal).If it does this can/should be an NPM issue, I am also not able to reproduce this with a simple program and agree with Liran that it's probably a function of NPM versions
aviadhahami commentedon Jul 8, 2022
@benjamingr to make sure I understand - you like me to test in these setups whether npm respect SIGTERM?
benjamingr commentedon Jul 8, 2022
@aviadhahami basically I want to isolate whether or not this is a Node.js issue or an npm issue - I suspect it's an NPM issue so the next step would be to prove it and simulate what Node.js is doing (in your code) without Node.js
aviadhahami commentedon Jul 8, 2022
@benjamingr -- I've tried the following:
kill <PID>The
nodeprocesses (the sleeping one) died and the whole processes tree collapsedAttaching a screenshot, the spawned npm log and the
ps auxfrom the machine:wdyt?
bnoordhuis commentedon Mar 27, 2023
I suspect this is explained by a change in how npm starts child processes. The SIGTERM or SIGKILL is delivered to the first child process, not all (grand)child processes. That's not something node can fix, it's just the unfortunate reality of Unix process trees.
What can work with well-behaved programs is to start them in a new process group and signal the entire process group:
Node can't do that automatically without breaking backwards compatibility (and blocking off some valid use cases) but now you know the option exists. I'll go ahead and close this.
aviadhahami commentedon Apr 10, 2023
@bnoordhuis thx for replying!
can you refer me to the relevant code/change please?
Correct nodejs/node#43704's status - it is closed, not open