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

agent-base leaks memory when it is required #22

@shusson

Description

@shusson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions