Why is node require cache filling up and leaking
Asked Answered
M

1

6

Im stress testing an API in loopback which is transpiled with Babel. However, during these longer "smoke" tests, we have seen the require cache in Heap analysis growing quite large (up to 1gb) and does not get GCd.

I understand the require cache wont GC until the last reference is removed, but why would it continue to grow if Im calling the same set of methods over and over?

Could this be an issue with Babel 6, or NodeJS 4.4.3?

Here is a screen shot showing the heap dump

enter image description here

Mcgray answered 14/4, 2016 at 16:14 Comment(2)
The require cache is just an object keyed by path. Are you sure some object that you're exporting from a module isn't growing without bound and showing as related to the require cache because you export it?Yuma
Im not certain of that. I largest heap item is "(string)" which contains all the cached code and seems to be growing and not GC. I'll update my post with a screen shot. If it were per an export, would this cache still maintain unless the export was changing? Or am I mis-understanding this heap data?Mcgray
P
0

We were hitting what appeared to be a similar issue with the heap filling and filling with strings that looked like old source code the service. The problem ended up being the Babel cache (~/.babel.json for the service's user). This file was growing by about 2MB for every restart of the app and eventually hit +200MB before our stuff started breaking. Removing the file and setting the following env var for the service solved our problem: BABEL_DISABLE_CACHE=1 (heap went from 600MB down to 80MB).

Pneumograph answered 6/2, 2019 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.