Getting frequesnt connection closed errors
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.
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
}
I'm facing same issue too when using quit method, looks like it's coming from this line
found the issue in my side, there was a pending command that was not resolved so when closing, it throws that error