mailgun / mailgun-js-boland

A simple Node.js helper module for Mailgun API.
http://bojand.github.io/mailgun-js
MIT License
895 stars 122 forks source link

mailgun-js is leaking memory when you require it #217

Open shusson opened 6 years ago

shusson commented 6 years ago

1) mailgun-js 0.18.0

2) node 10.9.1

const mailgun = require("mailgun-js");

describe("mailgun-js", () => {
    it(`should not leak`, async () => {
        expect(mailgun).toBeTruthy();
    });
});
jest --detectLeaks
tests/test-leak.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 I narrowed it down to the dependency chain proxy-agent->agent-base. I've raised an issue https://github.com/TooTallNate/node-agent-base/issues/22 to track this.

We noticed it because or jest e2e tests were failing due to running our of memory.

jimmywarting commented 5 years ago

might not surprise me, just look at this dependency tree https://npm.anvaka.com/#/view/2d/mailgun-js

If possible, remove proxy-agent, it's not mandatory, users could include a agent themselves.