Skip to content

worker_threads consuming so much memory and crash #32265

@khoanguyen-3fc

Description

@khoanguyen-3fc

What steps will reproduce the bug?

const { Worker, isMainThread } = require('worker_threads');

if (isMainThread) {
    for (let i = 0; i < 2000; i++) {
        new Worker(__filename);
    }
} else {
    console.log(JSON.stringify(process.memoryUsage()));

    setInterval(() => {
        // Keep thread alive
    }, 1000);
}

How often does it reproduce? Is there a required condition?

This problem always occur.

What is the expected behavior?

I have to run at least 2000 worker thread at the same time.

What do you see instead?

The script crash with random GC error.

Additional information

I need to run at least 2000 thread at the same time, but there are 2 problem that I encounter:

  • The worker_thread are consuming so much memory, about 5MB in RSS for an empty thread, so I end up with 1500 threads and about 8GB RAM, and cost some more if the thread do something, but it wasn't the real problem, because my server have a large amount of RAM (>100GB)
  • The main problem is the script would crash at about 8GB RSS, I'd also try with --max-old-space-size=81920 --max-semi-space-size=81920, but the error still there when RSS reach 8GB

Output of script

// 1486 lines, 1487th line bellow
{"rss":8157556736,"heapTotal":4190208,"heapUsed":2382936,"external":802056}

<--- Last few GCs --->
[19127:0x7f5f4442fa80]    26606 ms: Scavenge 2.0 (2.7) -> 1.6 (3.7) MB, 1.8 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
{"rss":8158093312,"heapTotal":4190208,"heapUsed":2388408,"external":802056}
 1: 0x9ef190 node::Abort() [node]

<--- Last few GCs --->
[19127:0x7f5fa442fb40]    24675 ms: Scavenge 2.0 (2.7) -> 1.6 (3.7) MB, 1.9 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
{"rss":8158359552,"heapTotal":4190208,"heapUsed":2383584,"external":802056}
{"rss":8158359552,"heapTotal":4190208,"heapUsed":2375648,"external":802056}
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]

<--- Last few GCs --->
[19127:0x7f5fb842fb20]    27482 ms: Scavenge 2.0 (2.7) -> 1.6 (3.7) MB, 2.0 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
 1: 0x9ef190 node::Abort() [node]
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 1: 0x9ef190 node::Abort() [node]
{"rss":8158846976,"heapTotal":4190208,"heapUsed":2375568,"external":802056}
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]

<--- Last few GCs --->
[19127:0x7f5fac42fb20]    27489 ms: Scavenge 2.0 (2.7) -> 1.6 (3.7) MB, 2.0 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]
{"rss":8160190464,"heapTotal":4190208,"heapUsed":2390760,"external":802056}
{"rss":8160190464,"heapTotal":4190208,"heapUsed":2385720,"external":802056}
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xd0a765  [node]
 1: 0x9ef190 node::Abort() [node]
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 6: 0xd545ee  [node]

<--- Last few GCs --->
[19127:0x7f60b842fe20]    29692 ms: Scavenge 2.0 (2.7) -> 1.5 (3.7) MB, 1.8 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
{"rss":8161587200,"heapTotal":3928064,"heapUsed":2385144,"external":802056}
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xd0a765  [node]
 7: 0xd58797 v8::internal::MarkCompactCollector::CollectGarbage() [node]
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]

<--- Last few GCs --->
[19127:0x7f5ef4165610]    26880 ms: Scavenge 2.0 (2.7) -> 1.5 (3.7) MB, 1.8 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
 1: 0x9ef190 node::Abort() [node]
 5: 0xd0a765  [node]
 6: 0xd545ee  [node]
 8: 0xd16c39 v8::internal::Heap::MarkCompact() [node]
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]
{"rss":8161710080,"heapTotal":3928064,"heapUsed":2373360,"external":802056}
 1: 0x9ef190 node::Abort() [node]
 6: 0xd545ee  [node]
 7: 0xd58797 v8::internal::MarkCompactCollector::CollectGarbage() [node]
 9: 0xd179a3 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
 5: 0xd0a765  [node]
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]
 7: 0xd58797 v8::internal::MarkCompactCollector::CollectGarbage() [node]
 8: 0xd16c39 v8::internal::Heap::MarkCompact() [node]
10: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 6: 0xd545ee  [node]
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 8: 0xd16c39 v8::internal::Heap::MarkCompact() [node]
 9: 0xd179a3 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
11: 0xd1afcc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 7: 0xd58797 v8::internal::MarkCompactCollector::CollectGarbage() [node]
 5: 0xd0a765  [node]
{"rss":8161210368,"heapTotal":3665920,"heapUsed":2381024,"external":802056}
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 9: 0xd179a3 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
10: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
{"rss":8161210368,"heapTotal":3665920,"heapUsed":2388704,"external":802056}
12: 0xce7cae v8::internal::Factory::NewMap(v8::internal::InstanceType, int, v8::internal::ElementsKind, int) [node]
{"rss":8161210368,"heapTotal":3665920,"heapUsed":2360896,"external":802056}
 8: 0xd16c39 v8::internal::Heap::MarkCompact() [node]
 6: 0xd545ee  [node]
 5: 0xd0a765  [node]
10: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
11: 0xd1afcc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
13: 0xede9db v8::internal::Map::RawCopy(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, int, int) [node]
 9: 0xd179a3 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
 7: 0xd58797 v8::internal::MarkCompactCollector::CollectGarbage() [node]
 6: 0xd545ee  [node]
{"rss":8161210368,"heapTotal":3665920,"heapUsed":2365384,"external":802056}
11: 0xd1afcc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
{"rss":8160485376,"heapTotal":3403776,"heapUsed":2389984,"external":802056}
12: 0xce7cae v8::internal::Factory::NewMap(v8::internal::InstanceType, int, v8::internal::ElementsKind, int) [node]
{"rss":8160489472,"heapTotal":3403776,"heapUsed":2389456,"external":802056}
{"rss":8160489472,"heapTotal":3403776,"heapUsed":2397112,"external":802056}
14: 0xedf104 v8::internal::Map::CopyDropDescriptors(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>) [node]

<--- Last few GCs --->

[19127:0x7f60a8001010]    47768 ms: Scavenge 2.4 (4.2) -> 2.1 (4.0) MB, 1.6 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->

FATAL ERROR: Committing semi space failed. Allocation failed - JavaScript heap out of memory
10: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: 0xd16c39 v8::internal::Heap::MarkCompact() [node]
 7: 0xd58797 v8::internal::MarkCompactCollector::CollectGarbage() [node]
12: 0xce7cae v8::internal::Factory::NewMap(v8::internal::InstanceType, int, v8::internal::ElementsKind, int) [node]
13: 0xede9db v8::internal::Map::RawCopy(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, int, int) [node]
{"rss":8150188032,"heapTotal":3403776,"heapUsed":2413400,"external":802056}
15: 0xedf1a6 v8::internal::Map::ShareDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Descriptor*) [node]
 1: 0x9ef190 node::Abort() [node]
11: 0xd1afcc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0xd179a3 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
 8: 0xd16c39 v8::internal::Heap::MarkCompact() [node]
13: 0xede9db v8::internal::Map::RawCopy(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, int, int) [node]
14: 0xedf104 v8::internal::Map::CopyDropDescriptors(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>) [node]
16: 0xedfcae v8::internal::Map::CopyAddDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 2: 0x9f13b2 node::OnFatalError(char const*, char const*) [node]
12: 0xce7cae v8::internal::Factory::NewMap(v8::internal::InstanceType, int, v8::internal::ElementsKind, int) [node]
13: 0xede9db v8::internal::Map::RawCopy(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, int, int) [node]
 9: 0xd179a3 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
14: 0xedf104 v8::internal::Map::CopyDropDescriptors(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>) [node]
15: 0xedf1a6 v8::internal::Map::ShareDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Descriptor*) [node]
17: 0xedfe29 v8::internal::Map::CopyWithField(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
 3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
14: 0xedf104 v8::internal::Map::CopyDropDescriptors(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>) [node]
15: 0xedf1a6 v8::internal::Map::ShareDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Descriptor*) [node]
16: 0xedfcae v8::internal::Map::CopyAddDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
16: 0xedfcae v8::internal::Map::CopyAddDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
18: 0xee15f2 v8::internal::Map::TransitionToDataProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::StoreOrigin) [node]
10: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 5: 0xd0a765  [node]
10: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
15: 0xedf1a6 v8::internal::Map::ShareDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Descriptor*) [node]
17: 0xedfe29 v8::internal::Map::CopyWithField(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
17: 0xedfe29 v8::internal::Map::CopyWithField(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
19: 0xed1cdf v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::StoreOrigin) [node]
11: 0xd1a959 v8::internal::Heap::ReserveSpace(std::vector<v8::internal::Heap::Chunk, std::allocator<v8::internal::Heap::Chunk> >*, std::vector<unsigned long, std::allocator<unsigned long> >*) [node]
 6: 0xd182ee v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
11: 0xd1afcc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
16: 0xedfcae v8::internal::Map::CopyAddDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
18: 0xee15f2 v8::internal::Map::TransitionToDataProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::StoreOrigin) [node]
18: 0xee15f2 v8::internal::Map::TransitionToDataProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::StoreOrigin) [node]
19: 0xed1cdf v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::StoreOrigin) [node]
20: 0xf05566 v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin) [node]
 7: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
12: 0xce7cae v8::internal::Factory::NewMap(v8::internal::InstanceType, int, v8::internal::ElementsKind, int) [node]
17: 0xedfe29 v8::internal::Map::CopyWithField(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
19: 0xed1cdf v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::StoreOrigin) [node]
20: 0xf05566 v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin) [node]
21: 0xeb08e0 v8::internal::JSObject::DefineOwnPropertyIgnoreAttributes(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::JSObject::AccessorInfoHandling) [node]
22: 0xeb0bec v8::internal::JSObject::SetOwnPropertyIgnoreAttributes(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes) [node]
23: 0x10283ef  [node]
24: 0x102c399  [node]
25: 0x102d303 v8::internal::Runtime_CreateObjectLiteral(int, unsigned long*, v8::internal::Isolate*) [node]
26: 0x13a71b9  [node]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions