Closed
Description
- Version: v8.12.0 64-bit
- Platform: Linux 4.15.0-1026 (Ubuntu 16.04)
- Subsystem: child_process
A tiny exec
call when Node.js is using at least half of the otherwise-available memory causes spawn ENOMEM
:
// If your system has more than 4 GB of mem, repeat these two lines until >50% of memory is used:
let x = Buffer.allocUnsafe(2e9);
x.fill(2); // virtual -> reserved
// Causes ENOMEM even if there's >1 GB of available memory:
require("child_process").exec("pwd", console.log)
# (strace)
[pid 3017] clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ffae3ea7a10) = -1 ENOMEM (Cannot allocate memory)
Apparently this is a common problem when using fork()
/clone()
, and using .posix_spawn(3)
avoids it
- Good write up of the issue: https://www.oracle.com/technetwork/server-storage/solaris10/subprocess-136439.html
- Related glibc bug discussion from JDK devs working on same issue https://sourceware.org/bugzilla/show_bug.cgi?id=10311
- JDK bug that goes with above https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6850720
I don't see any upstream issues in libuv for this.