Skip to content

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Socket]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit #2030

@bdekok

Description

@bdekok

Hello I've been experiencing some issues when updating to ioredis 5.8.0 or higher. My guess is that there is a problem in the subscription logic that was introduced there.

I'm running a Nextjs setup in which I do the following:

  1. In the nextjs instrumentation hook (which gets called once when a server is instantiated) I first initialise a ioredis client. The import of the ioredis client is dynamic as the instrumentation hook runs both in edge and nodejs runtimes. We only want to import the client in nodejs runtimes, importing it dynamically will make sure that the edge runtime never gets the code.
  2. The instance then gets put on a globalThis namespace (only when running in a nodejs runtime) to make sure it is available throughout the application.

Directly when starting the application it will show MaxListenersExceededWarning's, our monitoring showed it was opening an enormous amount of connections. (58k).

I have created a simple reproduction of this issue here

Image

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions