question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.

See original GitHub issue

Hi there,

I think there is a regression in version 3.0.

When I’m using Custom Agent (https) with keepAlive: true option and then just make a bunch of requests. Pretty soon such warnings show up:

(node:24083) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit at _addListener (node:events:469:17) at TLSSocket.addListener (node:events:491:10) at TLSSocket.Readable.on (node:internal/streams/readable:876:35) at ClientRequest.<anonymous> (…/node_modules/node-fetch/src/index.js:316:10) at ClientRequest.emit (node:events:394:28) at tickOnSocket (node:_http_client:755:7) at onSocketNT (node:_http_client:815:5) at processTicksAndRejections (node:internal/process/task_queues:84:21)

The same thing with http, just listeners added not to TLSSocket but to just Socket.

Reproduction

Here is a really simple example.

import https from 'node:https'
import fetch from 'node-fetch'

const agent = new https.Agent({ keepAlive: true })

async function start () {
  for (let i = 1; i < 1000; i++) {
    await fetch('https://example.com', { agent })
  }
}

process.on('warning', e => console.warn(e.stack))

start().catch(e => console.error(e))

Steps to reproduce the behavior:

  1. Run this code with node-fetch@3 installed and you will start getting warnings.
  2. Install node-fetch@2 as a dependency, run the same code, and boom, no warnings.

Expected behavior

Version 2.6.2 does not produce any warning on the same code. Version 3.0.0 produces warnings.

Your Environment

I have been running this on node.js 14 (LTS) and 16 (latest) with the same results.

software version
node-fetch 3.0.0
node v14.17.6 & v16.9.1
npm 6.14.15 & 7.21.1
Operating System MacOS 11.5.2 (20G95) & Docker with alpine linux

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:25 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
zach-shute-coinbasecommented, Mar 14, 2022

@jimmywarting The PR has been inactive for 2 months. Can you chose the other fix and get out a release to unblock anyone experiencing the issue?

4reactions
olegadecommented, Feb 8, 2022

Is it possible to get an update on this issue? We eagerly await a new version without the memory leak.

Read more comments on GitHub >

github_iconTop Results From Across the Web

possible EventEmitter memory leak detected - node.js
I'd like to point out here that that warning is there for a reason and there's a good chance the right fix is...
Read more >
Possible EventEmitter memory leak detected. 11 error ...
Describe the bug When using simple cache adapters MaxListenersExceededWarning is emitted. This has previously been investigated in #792 and #1128 but either ...
Read more >
How to fix possible EventEmitter memory leak detected
The warning possible EventEmitter memory leak detected happens when you have more than 10 listeners (read EventEmitter) attached to an event ...
Read more >
Actions execution throws "MaxListenersExceededWarning"
(node:18) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Socket]. Use emitter.
Read more >
Possible EventEmitter memory leak detected. 11 scanStop ...
The node red console indicates "MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 scanStop listeners added. Use emitter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found