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

Infinite writes to stdout causes a heap out of memory error #9778

Closed
mouradhamoud opened this issue Nov 24, 2016 · 4 comments
Closed

Infinite writes to stdout causes a heap out of memory error #9778

mouradhamoud opened this issue Nov 24, 2016 · 4 comments
Labels
memory Issues and PRs related to the memory management or memory footprint. process Issues and PRs related to the process subsystem. stream Issues and PRs related to the stream subsystem.

Comments

@mouradhamoud
Copy link

  • Version: 6.9.1 , 7.2.0 , 4.4.7
  • Platform: Linux laptop 4.4.0-47-generic contributing: commiter git FAQ #68-Ubuntu SMP Wed Oct 26 19:39:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: Stream, Console

Maybe this is related to how Node.js handles IO asynchronously, so it was not designed to handle this kind of code.

Execute the following:

var str = "Hello";

while(true) process.stdout.write(str);

or this code:

var str = "Hello";

while(true) console.log(str);

The node process starts eating memory (about 1.4 gigabyte in my case) and then it crashes with a heap out of memory error, see below:

FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x1098b2c [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) [node]
 6: v8::internal::MarkCompactCollector::VisitLiveObjects(v8::internal::MemoryChunk*, v8::internal::MarkCompactCollector::HeapObjectVisitor*, v8::internal::MarkCompactCollector::IterationMode) [node]
 7: v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal() [node]
 8: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node]
 9: v8::internal::MarkCompactCollector::EvacuateNewSpaceAndCandidates() [node]
10: v8::internal::MarkCompactCollector::CollectGarbage() [node]
11: v8::internal::Heap::MarkCompact() [node]
12: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
13: v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char const*, char const*, v8::GCCallbackFlags) [node]
14: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
15: v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0x2373309092a7
Aborted (core dumped)
@mscdex mscdex added memory Issues and PRs related to the memory management or memory footprint. process Issues and PRs related to the process subsystem. stream Issues and PRs related to the stream subsystem. labels Nov 24, 2016
@bnoordhuis
Copy link
Member

Maybe this is related to how Node.js handles IO asynchronously, so it was not designed to handle this kind of code.

That is indeed what happens. The memory associated with the write-to-console request won't be freed until the next tick of the event loop. That next tick never happens in your code because it's executing an infinite loop.

@mouradhamoud
Copy link
Author

Thank you for confirming this.

@Fishrock123
Copy link
Contributor

@mouradhamoud Do you have any other related questions / comments, or can we close this?

@mouradhamoud
Copy link
Author

Thanks, I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory Issues and PRs related to the memory management or memory footprint. process Issues and PRs related to the process subsystem. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants