aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.
Apache License 2.0
267 stars 156 forks source link

memory leaks caused by cls-hooked #594

Closed regevbr closed 12 months ago

regevbr commented 1 year ago

Hi,

We noticed a massive memory leak when using this library. We managed to find that the memory leaks come from the unmaintained cls-hooked library. Since we are using the library in manual mode, we don't even want it to be used, but currently, you create a namespace by default. When setting manual mode, the namespace gets deleted, but cls-hooks doesn't do that properly, creating a memory leak.

A proposed solution will be to not use cls if an env variable exists to control manual mode.

PR with the fix is submitted

dobrynin commented 1 year ago

fwiw there is an open issue that couldn't be reproduced by AWS. Hopefully they will investigate now that there are multiple reports of the issue w/ the cls-hooked library.

carolabadeer commented 1 year ago

When setting manual mode, the namespace gets deleted, but cls-hooks doesn't do that properly, creating a memory leak.

Issues on cls-hooked repo regarding this specific memory leak for reference and tracking: https://github.com/Jeff-Lewis/cls-hooked/issues/66 https://github.com/Jeff-Lewis/cls-hooked/issues/67 https://github.com/Jeff-Lewis/cls-hooked/issues/68

nick-kang commented 11 months ago

This fixed it for me: https://github.com/Jeff-Lewis/cls-hooked/issues/63#issuecomment-753657016.