Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting frequesnt connection closed errors #1848

Open
geo-github opened this issue Jan 19, 2024 · 2 comments
Open

Getting frequesnt connection closed errors #1848

geo-github opened this issue Jan 19, 2024 · 2 comments

Comments

@geo-github
Copy link

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
}
@roggervalf
Copy link

roggervalf commented Feb 3, 2024

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

@roggervalf
Copy link

roggervalf commented Feb 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants