Skip to content
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

Silly program or memory leak? #2970

Closed
fivdi opened this issue Sep 20, 2015 · 5 comments
Closed

Silly program or memory leak? #2970

fivdi opened this issue Sep 20, 2015 · 5 comments
Labels
console Issues and PRs related to the console subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. memory Issues and PRs related to the memory management or memory footprint.

Comments

@fivdi
Copy link

fivdi commented Sep 20, 2015

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
@ChALkeR
Copy link
Member

ChALkeR commented Sep 20, 2015

Dupe of #1741.

@ChALkeR ChALkeR closed this as completed Sep 20, 2015
@ChALkeR ChALkeR added duplicate Issues and PRs that are duplicates of other issues or PRs. memory Issues and PRs related to the memory management or memory footprint. labels Sep 20, 2015
@ChALkeR
Copy link
Member

ChALkeR commented 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
Copy link
Author

fivdi commented Sep 20, 2015

@ChALkeR thanks for the short answer, it's easier to understand than the long one :)

@ChALkeR
Copy link
Member

ChALkeR commented 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.

@ChALkeR ChALkeR added the console Issues and PRs related to the console subsystem. label Sep 20, 2015
@fivdi
Copy link
Author

fivdi commented 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.

jmakeig added a commit to jmakeig/lineup-builder that referenced this issue May 6, 2016
See nodejs/node#2970 about filling up the console.log buffer before it can be drained.
richardlau added a commit to richardlau/node-1 that referenced this issue Mar 1, 2024
Original commit message:

    fs: fix WTF-8 decoding issue (nodejs#4092)

    We forgot to mask off the high bits from the first byte, so we ended up
    always failing the subsequent range check.

    Refs: nodejs#2970
    Fixes: nodejs#48673
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. memory Issues and PRs related to the memory management or memory footprint.
Projects
None yet
Development

No branches or pull requests

2 participants