socket.io-redis-adapter icon indicating copy to clipboard operation
socket.io-redis-adapter copied to clipboard

Unnecessary on("error") handlers

Open KlausVii opened this issue 1 year ago • 0 comments

The adapter constructor always adds an error to the redis clients here: https://github.com/socketio/socket.io-redis-adapter/blob/cdb55353f83c78cabe9788683e4dd93ac4cd50c9/lib/index.ts#L193

The handler just logs a warning if there are no other error handlers it

      if (this.listenerCount("error") === 1) {
        console.warn("missing 'error' handler on this Redis client");
      }

Since this constructor is called every time a namespace is created in socket io, we end up adding multiple copies of this handler to the underlying redis client possibly triggering a MaxListenersExceededWarning.

Would it be possible to add these handlers conditionally only if the client does not have any already?

KlausVii avatar Apr 17 '24 13:04 KlausVii