Skip to content

Memory leak with util.TextDecoder #32424

Closed
@appellation

Description

@appellation
  • Version: 13.11.0
  • Platform: Windows 10 (1903)
  • Subsystem: util

What steps will reproduce the bug?

Credit to @Hakerh400 on nodejs/help#2541:

while(1) new util.TextDecoder().decode(Buffer.from('abcde'));

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

This occurs whenever the built-in TextDecoder is used to decode a buffer.

What is the expected behavior?

Memory is reclaimed by the garbage collector, allowing the process to continue indefinitely.

What do you see instead?

After a short period of time, the process crashes with the following console output:

<--- Last few GCs --->

[13528:0000024D02FE71F0]    37800 ms: Scavenge 2045.8 (2048.9) -> 2045.4 (2049.4) MB, 5.7 / 0.3 ms  (average mu = 0.123, current mu = 0.051) allocation failure
[13528:0000024D02FE71F0]    37907 ms: Scavenge 2046.8 (2049.9) -> 2046.3 (2050.4) MB, 27.9 / 0.7 ms  (average mu = 0.123, current mu = 0.051) allocation failure


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF60F25199C]
Security context: 0x0227b7000921 <JSObject>
    1: /* anonymous */ [0000033718BE12D9] [[eval]:~1] [pc=00000138C18048EC](this=0x03940eec04b9 <JSGlobal Object>)
    2: InternalFrame [pc: 00007FF60F24E70E]
    3: EntryFrame [pc: 00007FF60F24E2FC]
    4: builtin exit frame: runInThisContext(this=0x034c5e840121 <ContextifyScript map = 00000004AC63E331>,0x01ebe0c806f1 <false>,0x01ebe0c806f1 <false>,0x01eb...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF60E6AD98F napi_wrap+111663
 2: 00007FF60E64C406 v8::base::CPU::has_sse+57574
 3: 00007FF60E64D2A3 v8::base::CPU::has_sse+61315
 4: 00007FF60EE7B93E v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF60EE63091 v8::SharedArrayBuffer::Externalize+785
 6: 00007FF60ED2A0FC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
 7: 00007FF60ED35440 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
 8: 00007FF60ED31F34 v8::internal::Heap::PageFlagsAreConsistent+3188
 9: 00007FF60ED27643 v8::internal::Heap::CollectGarbage+1283
10: 00007FF60ED25DD4 v8::internal::Heap::AllocateExternalBackingStore+1396
11: 00007FF60ED4D3FC v8::internal::Factory::NewMap+76
12: 00007FF60EE89279 v8::PropertyDescriptor::writable+6569
13: 00007FF60EE89DDA v8::PropertyDescriptor::writable+9482
14: 00007FF60EE89AF3 v8::PropertyDescriptor::writable+8739
15: 00007FF60EE8A295 v8::PropertyDescriptor::writable+10693
16: 00007FF60EE8A4C5 v8::PropertyDescriptor::writable+11253
17: 00007FF60EE78799 v8::ObjectTemplate::NewInstance+441
18: 00007FF60E60A65D v8::internal::UnoptimizedCompilationInfo::feedback_vector_spec+32797
19: 00007FF60F25199C v8::internal::SetupIsolateDelegate::SetupHeap+44124
20: 00000138C18048EC

Additional information

  • This issue does not appear to occur with TextEncoder#encode.
  • Using another text decoding module seems to resolve the memory leak (@itslukej tried using @exodus/text-encoding-utf8 with success)

Metadata

Metadata

Assignees

No one assigned

    Labels

    encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.memoryIssues and PRs related to the memory management or memory footprint.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions