Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withScope memory leak, very obvious when using scope.setTag in @sentry/node #2201

Closed
1 of 5 tasks
mattkrick opened this issue Aug 12, 2019 · 3 comments
Closed
1 of 5 tasks

Comments

@mattkrick
Copy link

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

5.5.0

Description

Creating a new issue since #1762 was closed.
There exists a small memory leak in @sentry/node. Calling setTag with some long strings makes it a lot larger.
This is identifiable because it's not only a memory leak, but according to my DO droplet metrics, it causes a permanent increase in CPU usage & Bandwidth public that can only be fixed by restarting the server.
Pic shows what happens when I added setTag (July 11) and when I removed it (Aug 9).
System memory (1)

@kamilogorek
Copy link
Contributor

Are you able to provide some repro-case for this? setTag with multiple concurrent requests will for sure increase a memory footprint, but once a scope is GC'd, memory should drop to the baseline.

@mattkrick
Copy link
Author

@kamilogorek the offending code is here: https://github.com/ParabolInc/action/blob/0bde4b002aa3d53fc00f1febcb39185079d827f2/packages/server/utils/sendToSentry.ts#L28-L35

from the looks of it, the scope isn't getting GC'd.

it may be unpopular, but all i really want is a clean API call that takes an exception & variables. e.g. Sentry.captureExpection(error, {tags: {foo: 1}}). that would get rid of the scopes & associated memory leaks.

@kamilogorek
Copy link
Contributor

withScope at the end of it's lifecycle performs a popScope operation which get rid of the layer from the internal array, thus there's no strong reference to it - GC takes care of it automatically.
fwfw you can change your call to:

Sentry.withScope((scope) => {
  scope.setUser(user)
  scope.setTags(tags)
  Sentry.captureException(error)
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants