Skip to content

[node][7.102.0] Suspicion of Memory Leak #10790

Closed

Description

@xr0master

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.102.0

Framework Version

espress.js

Link to Sentry event

No response

SDK Setup

Sentry.init({
  dsn: process.env.SENTRY_DNS,
  release: 'n/a',
  environment: process.env.NODE_ENV,
  integrations: [
    new Sentry.Integrations.Http({ tracing: true }),
    new Sentry.Integrations.Express({
      app,
      methods: ['post', 'get', 'delete'],
    }),
  ],

  tracesSampleRate: 0,
});

Steps to Reproduce

  1. add app.use(Sentry.Handlers.requestHandler());
  2. run request
  3. check profile

Expected Result

n/a

Actual Result

I would like to point out that the problem is not one-to-one. That is, not every request gets stuck in memory. After dozens of requests, only one object can be added, and sometimes more. I didn't find any particular pattern.

Screenshot 2024-02-22 at 21 37 15 Screenshot 2024-02-22 at 21 37 42

You may notice that multiple hubs are created, and the data (in locals) is not removed from the response object (and the response object is not deleted either).

if remove app.use(Sentry.Handlers.requestHandler());, there are no memory issues.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Feb 22, 2024
  2. Lms24 commented on Feb 23, 2024

    @Lms24
    Member

    Hey @xr0master thanks for writing in!

    Unfortunately this is going to be quite hard to figure out without a reproducible example. Any chance you could provide one?

    Another question:

    You may notice that multiple hubs are created

    Are you creating multiple hubs on purpose? Or is this just something you observed with the single Sentry.init call you mentioned in the issue?

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Feb 23, 2024
  4. moved this to Waiting for: Community in GitHub Issues with 👀 2on Feb 23, 2024
  5. xr0master commented on Feb 23, 2024

    @xr0master
    ContributorAuthor

    Hey @Lms24

    Unfortunately this is going to be quite hard to figure out without a reproducible example. Any chance you could provide one?

    It's definitely not easy... I'll try to do it.

    Are you creating multiple hubs on purpose? Or is this just something you observed with the single Sentry.init call you mentioned in the issue?

    Second option. Just regular integration with express.js. As far as I remember, only one hub should be created for the entire application, is it correct?

  6. moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 2on Feb 23, 2024
  7. xr0master commented on Feb 23, 2024

    @xr0master
    ContributorAuthor

    @Lms24
    https://github.com/xr0master/sentry-memo-leak

    npm run build
    npm run dev

    get request http://localhost:5001/logs

    Since the application is small, catching this issue is even more difficult. Dozens of requests with different intensities with several snapshots, and I managed to reproduce it. Good luck with this.

    image
  8. 65 remaining items

  9. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Apr 18, 2024
  10. Lms24 commented on Apr 22, 2024

    @Lms24
    Member

    As you said it's next.js so we don't configure it for express

    Apologies, I completely missed this in your first comment.

    Unfortunately, I think we're talking about multiple different memory leaks and scenarios by now. The only reproduction we received so far was for the Node SDK which no longer leaks memory if the order of registering the Sentry Node/Express handlers is corrected. Furthermore, users are mentioning different version ranges when the leak started happening.

    If you're able to provide a minimal reproduction for the leak you experience in your NextJS, we'd greatly appreciate it!

  11. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Apr 22, 2024
  12. sarunast commented on Apr 24, 2024

    @sarunast

    Perhaps it is @Lms24 but what caught my attention was this comment:

    I also went through some versions to see when it was introduced. It seems to start in 7.100.0. 7.99 and before works just fine.

    Which is true for us.

  13. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Apr 24, 2024
  14. AbhiPrasad commented on Apr 24, 2024

    @AbhiPrasad
    Contributor

    Looking at https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#71000

    The related changes are:

    What Node version is everyone using? What SDK features is everyone using (errors, performance, profiling, etc.). For Next.js in particular are you using the app or pages router?

    Because of the variety of different permutations of possible setups, sharing your package.json, next.config.js, etc. would be extremely helpful to allow us to narrow this down!

  15. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Apr 24, 2024
  16. lforst commented on Apr 25, 2024

    @lforst
    Contributor

    @AbhiPrasad I think it is this change where we introduce strong references to scopes on spans #10492

  17. AbhiPrasad commented on Nov 1, 2024

    @AbhiPrasad
    Contributor

    Considering we now have a new major version that made some improvements here (8.0.0), and we've also done some work to address memory issues there, I think the recommendation is to upgrade your SDK to v8:

    https://docs.sentry.io/platforms/javascript/guides/node/migration/v7-to-v8/

    Closing this issue for now as such.

  18. ghost added on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions