Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

agent-base leaks memory when it is required #22

Closed
shusson opened this issue Aug 22, 2018 · 1 comment · Fixed by #25
Closed

agent-base leaks memory when it is required #22

shusson opened this issue Aug 22, 2018 · 1 comment · Fixed by #25

Comments

@shusson
Copy link

shusson commented Aug 22, 2018

We've been narrowing down some memory leaks with jest --detectLeaks which uses the library weak internally. It looks like agent-base is leaking memory every time you require it.

Repository with tests showing the the issue: https://github.com/shusson/agent-base-leak

Example:

const agent = require("agent-base");

describe("agent-base", () => {
    it(`should not leak`, async () => {
        expect(agent).toBeTruthy();
    });
});
jest --detectLeaks
tests/agent-base.spec.ts
  ● Test suite failed to run

    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 node_modules/jest-cli/build/TestScheduler.js:275:22

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.653s

I think this is caused by the monkey patching in https://github.com/TooTallNate/node-agent-base/blob/master/patch-core.js in combination with nodejs/node#8443.

@kirillgroshkov
Copy link

Affects us here too: jestjs/jest#8248

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants