You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
child process : unexpected exit code when process is out of memory #12271
Version: 7.8.0
Platform: Windows 10 64
Subsystem: Child processes
I fork some child processes to do some intensive calculations.
Because I likely have some memory leaks, I pass the following arguments to the forked processes :
changed the title [-]child process : exit code when process is out of memory[/-][+]child process : unexpected exit code when process is out of memory[/+]on Apr 7, 2017
Yes, that sounds about right. Node kills itself with a SIGABRT signal on out-of-memory conditions. On UNIX systems, you get an exit code of 128 + signal 6 = 134 but on Windows it's exit code 3, presumably due to how the CRT emulates raise(SIGABRT).
Agree that Windows aborts map with exit code 3 - assigned by the CRT, not node.
At the same time, as @abenhamdine pointed out, the exit code listing does not seem to reflect this properly. Currently number 3 is defined for parse error. Either this needs to cover parse error | windows aborts, or signalled terminations in windows need to coin a different exit code to reflect the fact.
@bnoordhuis - thanks. I did not know that when node aborts in Windows, it does without a dump! Probably due to the JVM background I took it for granted that it does, just like any other OS.
Looking at what happens in Java, I see that they trap SIGABRT within the process and invoke MiniDumpWriteDump to capture one, and then unset the trap, re-send the signal to let it die.
That raises another question: does that mean that --abort-on-uncaught-exception is redundant in Windows? uncaught exception anyways captures the callstack, and with this flag, what is being provided additionally?
As a bonus, altering nodeProcessAborted will also allow to write a proper test for this as well I believe heh. But maybe it requires some more discussion?
I'm up for it, just making sure I'm barking down the right path :)
Question: how could I detect that a child process ran out-of-memory. Should I check on the exit code (134) or should I scan the stderr output for "JavaScript heap out of memory"? Or is there a better way?
@nicojs same doubt here. Nico, can you please explain how did you get this exit code 134 ? When I listen to the event child.on('exit', (code) => console.log(code)) I only got the exit code 0 and signal SIGABRT.
Activity
[-]child process : exit code when process is out of memory[/-][+]child process : unexpected exit code when process is out of memory[/+]Trott commentedon May 27, 2017
@bnoordhuis @cjihrig @indutny
richardlau commentedon May 28, 2017
Suspect this is #12823 (comment)
bnoordhuis commentedon May 28, 2017
Yes, that sounds about right. Node kills itself with a SIGABRT signal on out-of-memory conditions. On UNIX systems, you get an exit code of 128 + signal 6 = 134 but on Windows it's exit code 3, presumably due to how the CRT emulates
raise(SIGABRT).gireeshpunathil commentedon May 28, 2017
Agree that Windows aborts map with exit code 3 - assigned by the CRT, not node.
At the same time, as @abenhamdine pointed out, the exit code listing does not seem to reflect this properly. Currently number 3 is defined for parse error. Either this needs to cover parse error | windows aborts, or signalled terminations in windows need to coin a different exit code to reflect the fact.
gireeshpunathil commentedon May 28, 2017
/cc @refack
refack commentedon May 28, 2017
MSDN hints at ways to override this:
https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-abort-behavior
bnoordhuis commentedon May 29, 2017
That doesn't seem to let you override the exit code though. Perhaps the simplest fix is this:
gireeshpunathil commentedon May 29, 2017
@bnoordhuis - does this have the risk of node silently exiting on assertion failures? no coredumps and no messages?
bnoordhuis commentedon May 29, 2017
I don't think so. The error message is printed before ABORT_NO_BACKTRACE() is invoked and core dumps aren't a thing on Windows, right?
refack commentedon May 29, 2017
I did a similar thing for @indutny for his
mini-testgireeshpunathil commentedon May 29, 2017
@bnoordhuis - thanks. I did not know that when node aborts in Windows, it does without a dump! Probably due to the JVM background I took it for granted that it does, just like any other OS.
Looking at what happens in Java, I see that they trap
SIGABRTwithin the process and invokeMiniDumpWriteDumpto capture one, and then unset the trap, re-send the signal to let it die.That raises another question: does that mean that
--abort-on-uncaught-exceptionis redundant in Windows? uncaught exception anyways captures the callstack, and with this flag, what is being provided additionally?3 remaining items
jkantr commentedon Jun 21, 2017
I see this has been here unreferenced for awhile... and technically would be a first contribution to core for me :) Can I take it up?
jkantr commentedon Jun 21, 2017
@refack it would appear actually this change would mean the common test API would have to be altered, specifically nodeProcessAborted():
https://github.com/nodejs/node/blob/76340e3f1007998c7cb9d69fa1a42d42663ca6c2/test/common/index.js#L609,L615
As a bonus, altering nodeProcessAborted will also allow to write a proper test for this as well I believe heh. But maybe it requires some more discussion?
I'm up for it, just making sure I'm barking down the right path :)
refack commentedon Jun 21, 2017
Makes sense. Good catch.
refack commentedon Jun 21, 2017
@jkantr, I've flagged this as
in progressindicating you "claimed it".jkantr commentedon Jun 21, 2017
Sounds good, should be able to cobble something together in a few
nicojs commentedon Jul 31, 2018
Question: how could I detect that a child process ran out-of-memory. Should I check on the exit code (134) or should I scan the stderr output for "JavaScript heap out of memory"? Or is there a better way?
jlenon7 commentedon Sep 22, 2021
@nicojs same doubt here. Nico, can you please explain how did you get this exit code 134 ? When I listen to the event
child.on('exit', (code) => console.log(code))I only got the exit code 0 and signal SIGABRT.