Skip to content

Since version 7.48.0 sentry leaks AsyncLocalStorage instance #8829

Closed
@kamilchlebek

Description

@kamilchlebek

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/node

SDK Version

7.64.0

Steps to Reproduce

Since version 7.48.0 (till the latest version) we experience memory leaks while using @sentry/node.
After my investigation it's clear that this commit 4856685 is the root cause of our issues.

This is because for every execution of Sentry.init another AsyncLocalStorage is created and latter attached to global object:

const asyncStorage = new (async_hooks as NewerAsyncHooks).AsyncLocalStorage<Hub>();

The most important part (and tricky one) is that we call Sentry.init multiple times.
Once when node.js bootstraps, then for every upcoming request that generates angular application (we use similar approach to this one: https://dev.to/raghavgarg1257/angular-universal-add-error-logger-like-sentry-1hdd, so CSR uses @sentry/browsers but for angular universal (SSR) we pass @sentry/node).

It used to work since 2019 without any issue.

If this issue can't be fixed we'll try to setup single sentry instance and then pass it to angular universal app to use it.

Expected Result

Don't leak AsyncLocalStorage instance. Maybe reuse AsyncLocalStorage when Sentry.init is called multiple times?

Actual Result

Our CPU usage since v7.48.0 (goes back to normal when rolledback to v7.47.0)
cpu

retainers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions