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
Although the following program is a little silly, it results in a "process out of memory" with Node.js v4.0.0 on a Linux system after a few minutes of execution.
while (true) {
console.log("Hello, World!");
}
Here's the output:
...
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
<--- Last few GCs --->
710976 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15343.7 / 0 ms [allocation failure] [GC in old space requested].
726188 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15212.6 / 0 ms [allocation failure] [GC in old space requested].
741831 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15642.7 / 0 ms [last resort gc].
757723 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15892.2 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x37c258b9 <JS Object>
1: nextTick [node.js:~465] [pc=0x341fac9c] (this=0x37c7f939 <a process with map 0x563136b1>,callback=0x3e7bf5e1 <JS Function afterWrite (SharedFunctionInfo 0x3e777679)>)
2: arguments adaptor frame: 5->1
3: onwrite(aka onwrite) [_stream_writable.js:~314] [pc=0x341f3f50] (this=0x37c08099 <undefined>,stream=0x3e7bf6b1 <a WriteStream with map 0x56322bc9>,er=0x37c08099 <undefined>)
4: _w...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Aborted
Short answer: console output is buffered and async. Your console is slower then the script, and the buffer isn't limited by anything except for the global memory limit. So, it fills up the buffer and dies.
More info at #1741.
For anyone picky enough: by «buffer» I mean the implicit buffer that is actually the async operation queue.
Reacted by Pouria Maleki, Revan Zhang, josephrocca, Abhinav Singi and Latpaw
Reacted by subos2008, Matías Vallone and Thiago Morato
@fivdi You could try to redirect the output to a file. It works for me as a work-around.
But this shouldn't be an issue if you are not firing writes to console faster then it could process them.
Activity
ChALkeR commentedon Sep 20, 2015
Dupe of #1741.
ChALkeR commentedon Sep 20, 2015
Short answer: console output is buffered and async. Your console is slower then the script, and the buffer isn't limited by anything except for the global memory limit. So, it fills up the buffer and dies.
More info at #1741.
For anyone picky enough: by «buffer» I mean the implicit buffer that is actually the async operation queue.
fivdi commentedon Sep 20, 2015
@ChALkeR thanks for the short answer, it's easier to understand than the long one :)
ChALkeR commentedon Sep 20, 2015
@fivdi You could try to redirect the output to a file. It works for me as a work-around.
But this shouldn't be an issue if you are not firing writes to console faster then it could process them.
fivdi commentedon Sep 20, 2015
@ChALkeR thanks again. Redirecting the output to a file works around the issue for me too and is fine for what I want to achieve.
Removes logging