getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.94k stars 1.56k forks source link

Upgrading to Version 7.89.0 adds a memory leak #9982

Open Jindorf opened 9 months ago

Jindorf commented 9 months ago

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/vue

SDK Version

7.89.0

Framework Version

3.3.11

Link to Sentry event

No response

SDK Setup

const app = createSSRApp();

app.use(...) // using vuetify, pinia, vue-i18n, unhead/vue

Sentry.init({
  app,
  dsn: ...
});

Steps to Reproduce

We are investigating a memory-leak on our side and are upgrading packages 1for1 in case some npm-package is the issue. When we updated sentry/vue from 7.80.1 to latest (7.91.0) we saw a big increase in leakage. I tracked it down to upgrading to sentry/vue v7.89.0 being the problem. Upgrading to 7.88.0 didn't change any result.

We are testing with clinic, the test is running autocannon for 60 seconds against the local-running express-server. I didn't upgrade any other package for the test except sentry/vue.

If that's any helpful, we also use sentry/node, the leakage doesn't increase when upgrading that to latest.

Expected Result

to not increase the leakage

Actual Result

Using version <= 7.88.0 image

Using version > 7.88.0 image

lforst commented 9 months ago

Thanks for the detailed report. We will take a look! Can you share any more details? What SDK features are you using?

@mydea Any high level SDK changes in your mind that might cause this?

mydea commented 9 months ago

Nothing in particular, possibly worth it to look at the scope changes, maybe we are retaining a scope somewhere 🤔

anonrig commented 9 months ago

Which Node.js version do you use?

Jindorf commented 9 months ago

Thanks for all the quick responses so far.

What SDK features are you using?

I dont't know. We setup sentry on the client-side like i showed and don't bother with any options or specific features.

Which Node.js version do you use?

I used Node 18.16 when creating this issue. I just installed Node 20.10.0, upgraded Sentry/vue again and ran the test 3x. All tests failed because memory usage was too high. I then reduced the time from 60s to 30s, resulting in a smilar result than what i posted earlier. After 30s my memory was above 3gb. Without the Sentry/vue upgrade my memory is not increasing that heavily, pretty much the same result as before

lforst commented 9 months ago

@Jindorf I am a teeeny bit confused because your wrote that you set Sentry up on the client-side but you are talking about server memory leakage. In theory @sentry/vue is a package that is to be used exclusively on the browser. Would you mind looking into this?

Also, since leakage is always super hard to debug, do you have any more information than that memory graph? Do you still have the full profiling run laying around somewhere? Thanks!

Jindorf commented 9 months ago

I'm confused as well, we still have not found the root issue of the leak on our side. It could very well be the case that something in sentry/vue after v.7.88.0 just emphasizes the issue we have on our own end.. We use sentry/node and sentry/vue. We use Vike as our ssr-rendering-engine and an Express-Server. On server startup we setup sentry on the node-side as in the express-example. Vue suggests to create a new instance of the entire application on each request, where we also initialize sentry/vue. So on every request we setup a new vue-instance, which also results in us initializing sentry/vue again.

I do not know how Vike's client-side rendering works under the hood, maybe I should open an issue there aswell if the problem could be laying there. I opened it here because it's weird that upgrading the sentry/vue package had increased the leak so dramatically.

Unfortunately I don't think I'm allowed to share the memory-profile because of company-policies.

lforst commented 9 months ago

Interesting. If you find a way to share a profile that doesn't leak anything that would be great. My recommendation for you would be not to initialize the Vue SDK on the server-side. That could lead to leaks, a) because I suspect you're initializing twice or for every incoming request (which would 100% leak memory) b) the Vue SDK is not designed to run on node.