node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

client.flush() disallows the 'end' event to be emitted

Open acarstoiu opened this issue 4 years ago • 1 comments

Using the latest redis 3.0.2.

Iif someone calls client.flush() no further events are emitted by the Redis client. At least the 'end' event should be emitted in order to notify users that the socket has been closed. The problem lies in redis/lib/extendedApi.js:

RedisClient.prototype.end = function (flush) {
    ...
    this.stream.removeAllListeners();
    this.stream.on('error', noop);
    this.connected = false;
    this.ready = false;
    this.closing = true;
    return this.stream.destroySoon();
};

Not all socket listeners should be removed. Either the 'close' listener attached in line 225 of redis/index.js should be preserved/restored or an ad-hoc listener emitting 'end' should be added after the

this.stream.removeAllListeners();

line above.

acarstoiu avatar Feb 05 '21 11:02 acarstoiu