Why is node require cache filling up and leaking

2019-06-23 19:08发布

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

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-23 19:26

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).

查看更多
登录 后发表回答