ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

Getting frequesnt connection closed errors

Open geo-github opened this issue 1 year ago • 3 comments

I have implemented Pub/Sub pattern using ioredis. For past few days i get below error frequently and pod where the app is deployed frequently restarts . Wanted to know if node app restarts due to this error?Or this error is due to node app crashing

/usr/src/app/node_modules/ioredis/built/redis/event_handler.js:189

self.flushQueue(new Error(utils_1.CONNECTION_CLOSED_ERROR_MSG)) ^ Error: Connection is closed. at close (/usr/src/app/node_modules/ioredis/built/redis/event_handler.js:189:25) at TLSSocket. (/usr/src/app/node_modules/ioredis/built/redis/event_handler.js:156:20) at Object.onceWrapper (node:events:628:26) at TLSSocket.emit (node:events:525:35) at node:net:301:12 at TCP.done (node:_tls_wrap:588:7) at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

Sample code below: async subscribeToChannel(channelName) { this.logger.debug('cannot aquire lock - redis is locked'); const redisSub = this.getRedisInstance(); //Subscribe to channel redisSub.subscribe(channelName, (err, data) => { this.logger.debug('client subscribed'); }); return await new Promise((resolve, reject) => {//Wait for message event redisSub.on('message', (channel, message) => { this.logger.debug(Received the following message from ${channel}); resolve(JSON.parse(message));//Return data redisSub.unsubscribe();//Unsubscribe redisSub.quit();//Close connection }); }) }

publishToChannel(channelName, data) {
    const pub = this.getRedisInstance();
    pub.publish(channelName, JSON.stringify(data));//Publish data
    pub.quit();//Close connection
}

geo-github avatar Jan 19 '24 11:01 geo-github

I'm facing same issue too when using quit method, looks like it's coming from this line

roggervalf avatar Feb 03 '24 16:02 roggervalf

found the issue in my side, there was a pending command that was not resolved so when closing, it throws that error

roggervalf avatar Feb 04 '24 19:02 roggervalf