-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Cancerous memory consumption under specific circumstances #29001
Comments
This is a workaround for an issue that occurs in node 12.5.0 and newer, described in detail here: nodejs/node#29001 The behavior of the code in question is the same, however the change is enough to prevent locking the process into a "cancerous" state of memory growth. This is one of the weirdest bugs I've ever debugged. Under certain circumstances, Node process (starting from version 12.5.0, previous versions not affected), would not exit (even if we call `process.exit()` at the end of the file), and instead start to consume memory until it fills the whole available memory, using 100% CPU while at it. Here's a reproduction based on the `HasteMap`: https://gist.github.com/niieani/a527e9b2e6caf28e3021a50b938e4a91 Standard memory or CPU profiling doesn't show anything (literally, there are no function calls shown in the profiler). Dumping the heap snapshot results in a 36MB file, even when the memory consumption of the process is 10 GB. The backstory is that in our case [`jest`](https://github.com/facebook/jest) would not end AFTER all the tests have completed, and instead would start consuming huge amounts of memory (on CI, multiple processes from separate PRs would deplete the 128GB of RAM on the machine) so I started going down the rabbit hole to try and pinpoint what is the cause of the issue, which lead me to this minimal reproduction scenario, but also to discover all the quirks that helped to avoid triggering the scenario.
#28955 fixes this for me. |
Great to know we have a fix, but it would be useful to understand what was causing the issue in the first place, before closing. Otherwise we cannot know if the issue simply shifted around and isn't triggered by something slightly different (given how delicate reproducing this bug is). |
@niieani I don’t really have an answer for that – maybe somebody in @nodejs/v8 happens to know more. It’s a good sign that this is almost surely a bug in V8 and is fixed by a V8 upgrade; in the worst case, one could bisect V8 to figure out which commit exactly fixed this. |
For people looking at this from a "react-native start" is slow perspective, you can either use node <= v12.4.0, likely node >= 12.9.0 (assuming it gets the V8 sync #28955), or (new info) based on my testing just now you might try a workaround in jest-haste-map documented here with an attached patch-package compatible patch until jest-haste-map has the workaround integrated |
This is one of the weirdest bugs I've ever debugged.
Under certain circumstances, Node process (starting from version 12.5.0, previous versions not affected), will not exit (even if we call
process.exit()
at the end of the file), and will start to consume memory until it fills the whole available memory, using 100% CPU while at it.Here's a reproduction:
https://gist.github.com/niieani/a527e9b2e6caf28e3021a50b938e4a91
Now, what's really funny, there are a few things that make this reproduction not trigger the bug:
reproduction.json
shorter makes the process exit normallypath.resolve
with a call to a different function, e.g. byconsole.log
(note that this originally usedjest-haste-map/build/lib/fast_path
and would still trigger the bug)Standard memory or CPU profiling doesn't show anything (literally, there are no function calls shown in the profiler). Dumping the heap snapshot results in a 36MB file, even when the memory consumption of the process is 10 GB.
The backstory is that in our case
jest
would not end AFTER all the tests have completed, and instead would start consuming huge amounts of memory (on CI, multiple processes from separate PRs would deplete the 128GB of RAM on the machine) so I started going down the rabbit hole to try and pinpoint what is the cause of the issue, which lead me to this minimal reproduction scenario.I've done a core dump, so here's what I got from
lldb
from a slightly larger (earlier version) of my reproduction:core dump (lldb)
I couldn't get
llnode
to work, so this is all I could get from the above.The integrated report also wasn't very helpful, but here's the relevant part (report from an even earlier reproduction while running in
jest
):Node Report
The text was updated successfully, but these errors were encountered: