-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node hangs when running a stand-alone script with captured output #21960
Comments
Anyone have any thoughts on this? If not (or even if so), should it be transferred to the help repo or somewhere else? |
I don't think that npm in particular does anything abnormal that would trigger this, the Node side of it is almost certainly something to do with My guess would be that @logiclrd If you are able to, could you try running this in something other than If it still fails then there is more certainly some windows pipe shutdown handling bug in node or perhaps libuv. |
@nodejs/platform-windows |
Without some kind of reproduction we can try to test and explore the issue, this is going to continue going unresolved. There's been no conversation in a long time and it's not clear that there's going to be any progress. Closing but we can reopen if more information comes in |
@Fishrock123 asked if I could try using something other than @jasnell, you wrote that there is no reproduction, but I didn't see any suggestion that the reproduction I included in the initial report didn't actually work -- there is a reproduction! |
Sorry, I wasn't clear there, I wasn't able to reproduce it. |
Will reopen but it's likely to be a while before someone is able to take a look |
I also experienced this issue of the script hanging indefinitely when running node v14.15.1 on linux with the shebang I was able to get the script to not hang by changing the shebang to Even though the resulting script didn't produce any warnings, the script would not complete with that flag. With the same version of node on macos with the same script the script ran successfully. So my issue appears to be related to linux only. Here is the script that hangs #!/usr/bin/env NODE_NO_WARNINGS=1 node
console.log('It worked');
process.exit(0); Here is the script that doesn't hang #!/usr/bin/env node
console.log('It worked');
process.exit(0); |
Exactly same issue as woodcockjosh. NODE_NO_WARNINGS=1 makes node hanging on Ubuntu/Linux. I've not tried on any other system. |
The issue here is with env(1), not node. You must pass Long story short, the fixed version is this: #!/usr/bin/env -S NODE_NO_WARNINGS=1 node
console.log('It worked');
process.exit(0); |
I'm sorry, what?? The original issue is that on Windows, a child process hangs around holding the stdout and stderr pipes open. This is closed as a duplicate after someone reports a problem with environment variable splitting on Linux?? It seems clear that it is a completely unrelated issue! |
Just to point out that this issue is about redirected output streams on Windows, and has absolutely nothing to do with environment variables on Linux. woodcockjosh's report of seeing the same issue is spurious; it is not related to this bug report at all. |
^-- @bnoordhuis |
Well, I just ran my reproduction script with the latest Ruby version and Node v16.14.0 (just because it's what I happen to have installed), and the issue failed to reproduce. So I guess that's that. The issue was closed for entirely the wrong reason, but there's apparently no bug here any more?? In any event, my organization has pretty much migrated away from a Ruby-based buildchain anyway. |
I am running into an issue on our build servers where Node hangs after running a stand-alone script if it is launched with its standard handles redirected to pipes. Specifically, I am using Ruby's
popen3
function, which wraps OS pipe functionality to obtain pipe streams and then passes the underlying handles to the C runtime library'spopen
API function. I don't believe there is anything particular about the way Ruby is doing this, and I have the expectation that similar code written in C++ directly calling the underlying API functions would exhibit the same problem. I have not actually tested this, though.I first observed this behaviour as part of an
npm install
. When NPM installs thenode-sass
module, it tries to run an install hook script, and the resultingnode scripts/install.js
process hangs until it is sent a break signal or terminated externally. This does not occur ifnpm install
is simply run at the command-line, nor does it occur with simple piping done via the command interpreter (npm install | more
, for instance).In further debugging, I tried installing a local copy of
node-sass
in which I made alterations to thescripts/install.js
script. The hang is reproducible even if the entireinstall.js
script is a singleconsole.log
line. Furthermore, if I outright remove thescripts/install.js
file, then the parent process of what would have beennode scripts/install.js
encounters an error (expected), complains loudly about it, and then hangs. The command-line of this parent process is:I'm not sure what the next step is in identifying the root cause of this issue. I suspect NPM might play some part in it, because if I try my test on a dummy script file directly (
node test.js
), then the hang is not observed.The following Ruby code should demonstrate the hang if the
node-sass
module is configured to be installed intonode_modules
in the current project directory:At the time of the hang, if I attach a debugger to the rogue
node.exe
process, I see the following threads:Note that the process that is hanging is not the direct descendant of the calling site that is waiting (in this case the Ruby interpreter). The child process launched by
popen3
has in fact exited, but the streams (stdour
,stderr
) aren't signalled because they were inherited by grandchildren, and one of those is the culprit that isn't exiting.The hung process is sitting around keeping
stdout
andstderr
open, and since the pattern of the call site is to wait for the end of those streams as the indicator that the child process tree is complete, the call site blocks indefinitely as well.I have experimented with altering the call site so that it instead explicitly waits for its direct child process to exit, and forces the streams closed. This does permit the calling code to proceed, but the rogue process still remains, which (since this is Windows) causes issues later on to do with file locking.
If there is further debugging I can do to try to narrow down the cause of this issue, I would appreciate any advice. :-) Thanks!
The text was updated successfully, but these errors were encountered: