Skip to content

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

@mouradhamoud

Description

@mouradhamoud
  • 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    memoryIssues and PRs related to the memory management or memory footprint.processIssues and PRs related to the process subsystem.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions