Skip to content

Memory leak running with Jest+Sentry #8248

@kirillgroshkov

Description

@kirillgroshkov

🐛 Bug Report

We use @sentry/node in our unit tests with Jest.

We discovered that just importing @sentry/node (as const Sentry = require('@sentry/node')) leaks memory when running in Jest tests.

I've created a minimal repro here to showcase the issue (listed further).

Good to note that Jest has memory leak issues with many libraries, not just this one. Some popular libraries, e.g graceful-fs were "fixed" to not leak memory with Jest.

Why this issue is important - it blocks us to run our test suite in our CI environment (CircleCI), which has 4Gb memory constraint. It runs out-of-memory already with ~150 test files that we have in our project. See steps to reproduce further.

Some related issues in Jest:
getsentry/sentry-javascript#1966
#8247
#6814
#6738
#7311
#6399

To Reproduce

Steps to reproduce the behavior:

Use minimal repro repository: https://github.com/kirillgroshkov/sentry-jest-leak-repro
Run npm run test-leaking or npm run test-leaking-detectLeaks to see the issue.

Expected behavior

Expected to not increase memory usage (garbage collect all memory). Similar to what happens when you run npm run test-working.

Link to repl or repo (highly encouraged)

https://github.com/kirillgroshkov/sentry-jest-leak-repro

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.4
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.5.0 => 24.5.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions