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

Memory leak with util.TextDecoder #32424

Closed
appellation opened this issue Mar 22, 2020 · 1 comment
Closed

Memory leak with util.TextDecoder #32424

appellation opened this issue Mar 22, 2020 · 1 comment
Labels
encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. memory Issues and PRs related to the memory management or memory footprint.

Comments

@appellation
Copy link

  • 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)
@addaleax addaleax added encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. memory Issues and PRs related to the memory management or memory footprint. labels Mar 22, 2020
addaleax added a commit to addaleax/node that referenced this issue Mar 22, 2020
`ObjectTemplate`s are not garbage-collected like regular objects
(for some reason). It is sufficient to create a single template
anyway, so do that to address the memory leak.

Fixes: nodejs#32424
@addaleax
Copy link
Member

See #32426 :)

MylesBorins pushed a commit that referenced this issue Mar 26, 2020
`ObjectTemplate`s are not garbage-collected like regular objects
(for some reason). It is sufficient to create a single template
anyway, so do that to address the memory leak.

Fixes: #32424

PR-URL: #32426
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
yoursunny added a commit to yoursunny/NDNts that referenced this issue Apr 11, 2020
targos pushed a commit to targos/node that referenced this issue Apr 25, 2020
`ObjectTemplate`s are not garbage-collected like regular objects
(for some reason). It is sufficient to create a single template
anyway, so do that to address the memory leak.

Fixes: nodejs#32424

PR-URL: nodejs#32426
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
targos pushed a commit that referenced this issue Apr 28, 2020
`ObjectTemplate`s are not garbage-collected like regular objects
(for some reason). It is sufficient to create a single template
anyway, so do that to address the memory leak.

Fixes: #32424

PR-URL: #32426
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. memory Issues and PRs related to the memory management or memory footprint.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants