-
Notifications
You must be signed in to change notification settings - Fork 30k
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
child process : unexpected exit code when process is out of memory #12271
Comments
Suspect this is #12823 (comment) |
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 |
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. |
/cc @refack |
MSDN hints at ways to override this: |
That doesn't seem to let you override the exit code though. Perhaps the simplest fix is this: diff --git a/src/util.h b/src/util.h
index 175db0c..7791304 100644
--- a/src/util.h
+++ b/src/util.h
@@ -95,7 +95,7 @@ template <typename T> using remove_reference = std::remove_reference<T>;
// Windows 8+ does not like abort() in Release mode
#ifdef _WIN32
-#define ABORT_NO_BACKTRACE() raise(SIGABRT)
+#define ABORT_NO_BACKTRACE() _exit(134)
#else
#define ABORT_NO_BACKTRACE() abort()
#endif |
@bnoordhuis - does this have the risk of node silently exiting on assertion failures? no coredumps and no messages? |
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? |
@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 That raises another question: does that mean that |
I'm not sure that's totally correct. From what I saw |
Since #12271 (comment) is a straightforward solution, I'm marking this a a |
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? |
@refack it would appear actually this change would mean the common test API would have to be altered, specifically nodeProcessAborted(): 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 :) |
Makes sense. Good catch. |
@jkantr, I've flagged this as |
Sounds good, should be able to cobble something together in a few |
Raising SIGABRT is handled in the CRT in windows, calling _exit() with ambiguous code "3" by default. This adjustment to the abort behavior gives a more sane exit code on abort, by calling _exit directly with code 134. PR-URL: nodejs#13947 Fixes: nodejs#12271 Refs: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/abort Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
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 |
[edit by @refack]
suggested fix #12271 (comment)
[end edit]
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 :
and as expected, the processes run out of memory after a given time, with the following error :
What has surprised me is that the child process exits with a code 3.
Per docs, code 3 seems pretty vague, and not related to memory shortage.
I wonder if it's intentional, and if it would be more useful to have a specific exit code in that case.
Edit : Perhaps it's because of the vm.createContext() which mess the code ?
The text was updated successfully, but these errors were encountered: