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

node-http adapter memory leak with Jest #370

Closed
woodenconsulting opened this issue Nov 18, 2020 · 0 comments
Closed

node-http adapter memory leak with Jest #370

woodenconsulting opened this issue Nov 18, 2020 · 0 comments

Comments

@woodenconsulting
Copy link
Contributor

Description

There is a memory leak in the node-http adapter when using it with Jest. Jest resets the require cache after each test suite run which causes memory leaks when a native module is monkey patched and not reset; read more here.

The issue with the node-http adapter is caused by the monkey patching of the http and https modules here. These patches are not reset onDisconnect nor does nock reset them when calling restore (related issue).

I opened this PR which resolves the issue by resetting the monkey patching for the http and https modules.

Config

{
  adapters: ['node-http'],
  persister: 'fs',
  expiresIn: '30days',
  expiryStrategy: 'warn',
  // eslint-disable-next-line no-process-env
  mode: (process.env.POLLY_MODE ?? undefined) as PollyConfig['mode'],
  matchRequestsBy: {
    headers: false,
  },
  persisterOptions: {
    fs: {
      recordingsDir: nodePath.resolve(__dirname, '../.recordings'),
    },
  },
}

Dependencies

{
  "@pollyjs/adapter-node-http": "^5.0.0",
  "@pollyjs/core": "^5.0.0",
  "@pollyjs/persister-fs": "^5.0.0",
}

Environment

node: 12.18.3
npm: 6.14.6
os: linux 5.4.39-linuxkit

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

No branches or pull requests

2 participants