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

Memory leak with fetch on Node v19+ when using Jest's --detectLeaks #47936

Closed
enisdenjo opened this issue May 9, 2023 · 2 comments
Closed

Memory leak with fetch on Node v19+ when using Jest's --detectLeaks #47936

enisdenjo opened this issue May 9, 2023 · 2 comments
Labels
fetch Issues and PRs related to the Fetch API memory Issues and PRs related to the memory management or memory footprint.

Comments

@enisdenjo
Copy link

Version

Node >=v19

Steps to reproduce

  1. Clone enisdenjo/jest-fetch-leak repo
  2. Read its readme for local repro
  3. Check out the GitHub Actions for CI repo

Expected behavior

Doesn't leak ever.

Actual behavior

Leaks in Node >=v19 when test is repeated enough times.

Additional context

⚠️ Not really sure whether this issue belongs here or on Jest's repo. But, I have a hunch that it belongs here given that we're experiencing memory spikes with Node >=v19 in production. Nevertheless, I've opened an issue there too.

If a test, which uses native fetch, is iterated enough times in Node >=v19, Jest's --detectLeaks will report a memory leak.

This behaviour does not happen on Node <=v18.

Please check the leak detector tests in the CI.

Environment

ubuntu-latest from GitHub Actions
@VoltrexKeyva VoltrexKeyva added memory Issues and PRs related to the memory management or memory footprint. fetch Issues and PRs related to the Fetch API labels May 9, 2023
@bnoordhuis
Copy link
Member

When you say "memory leak", you mean this, right?

    EXPERIMENTAL FEATURE!
    Your test suite is leaking memory. Please ensure all references are cleaned.

    There is a number of things that can leak memory:
      - Async operations that have not finished (e.g. fs.readFile).
      - Timers not properly mocked (e.g. setInterval, setTimeout).
      - Keeping references to the global scope.

      at onResult (node_modules/@jest/core/build/TestScheduler.js:150:18)
          at Array.map (<anonymous>)

Since that's a jest feature and I don't plan on investigating how it tracks that, you should either report it to jest (and have them circle back to us if it turns out it's a node issue) or demonstrate the leak without using third-party modules.

@bnoordhuis
Copy link
Member

I'll close this for now but let me know when there is reason to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetch Issues and PRs related to the Fetch API memory Issues and PRs related to the memory management or memory footprint.
Projects
None yet
Development

No branches or pull requests

3 participants