DataDog / dd-trace-js

JavaScript APM Tracer
https://docs.datadoghq.com/tracing/
Other
650 stars 306 forks source link

Intermittent memory leak possibly related to uncollected Promises #1646

Closed mhassan1 closed 10 months ago

mhassan1 commented 3 years ago

Describe the bug We are running APM in our application and seeing a sawtooth pattern in RSS and heap that looks like this:

image image

When we disable APM, we do not see this pattern; memory remains flat. Here are two environments behind the same load balancer (top one is APM disabled, bottom one is APM enabled):

image

Our APM configuration looks like this:

require('dd-trace').init({
  analytics: true,
  scope: 'async_hooks',
  trackAsyncScope: false
})

We are using the following plugins (automatically):

We have tried some interventions:

  1. removed scope: 'async_hooks' to allow the tracer to choose a more modern scope manager: this doesn't seem to have made a difference
  2. turned off mongodb_core plugin: we can't tell if this is helping or not, so we will do more tests

We have added debug logging to track number of Promises, since that seems to have helped in https://github.com/DataDog/dd-trace-js/issues/759. After 48 hours with APM enabled:

I would like to see if disabling APM in these environments shows the same high number of unresolved and current Promises. Stay tuned on that.

Finally, we have taken heap snapshots from a couple of environments; here is one showing a lot of heap being consumed by spans:

image

We had hoped to be able to open this issue with more conclusions and a simple reproduction, but we have had trouble reproducing this outside of our real customer environments. We have several customer environments that demonstrate the sawtooth pattern where we are able to perform experiments.

Environment

taishi8117 commented 2 years ago

Hi @mhassan1, do you have any update on this issue? We're suspecting that we're also affected by this as we're seeing periodic OOM errors from our prod and our heap snapshots also show that they're consumed by spans. Happy to provide more details if it's helpful.

rochdev commented 2 years ago

@taishi8117 Can you share the dependencies from your package.json? This would help isolating if the issue could come from a specific plugin.

tlhunter commented 10 months ago

Closing this issue for now since it's so old, a few major releases have happened, and we've fixed a few memory leaks since this issue was created. If it's still relevant please tag us and reopen, and also provide the requested package.json file.