DataDog/dd-trace-js

Memory leak in workerpool

nathan-knight opened this issue · 4 comments

#4314 added a hook into workerpool that is causing a memory leak in our production application. We use workerpool to offload processing some data and this hook causes the messages (which may be large) to get retained:

shimmer.wrap(workerHandlerPackage.prototype, 'exec', exec => function (message, [testSuiteAbsolutePath]) {

I have confirmed this by turning off dd-trace and the leak goes away. I have also taken a heap snapshot and checked what is retaining the data and it is this function.

@juan-fernandez could you please prevent this hook from being enabled outside of tests?

hey @nathan-knight , thanks for the report. I'll see what I can do. In the meantime, could you set

DD_TRACE_DISABLED_PLUGINS=mocha
DD_TRACE_DISABLED_INSTRUMENTATIONS=mocha,workerpool

this should make it so that dd-trace still works but the memory leak is gone

could you please prevent this hook from being enabled outside of tests?

ideally I'd make the memory leak go away, but that's my second option 😄

I'm pretty sure that #4558 fixes the issue. I've tested it with a simple usage of workerpool though, so I might be wrong. If you could test it yourself that'd be awesome. The branch is

https://github.com/DataDog/dd-trace-js/compare/juan-fernandez/fix-memory-leak-workerpool

Something like:

yarn add dd-trace@https://github.com/DataDog/dd-trace-js#head=juan-fernandez/fix-memory-leak-workerpool

should work.

If you prefer you can also provide a small reproducible case so I can test it myself 😄

hey @nathan-knight this is released in https://github.com/DataDog/dd-trace-js/releases/tag/v5.20.0. If you can give it a try that'd be super useful

hey @nathan-knight this is released in https://github.com/DataDog/dd-trace-js/releases/tag/v5.20.0. If you can give it a try that'd be super useful

I tested it locally and it appears to have been resolved, thanks!