-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Problem
await ioredis.quit() throws an Error when there are still items on the commandQueue.
Error: Connection is closed.
at close (./node_modules/ioredis/built/redis/event_handler.js:189:25)
at Socket.<anonymous> (./node_modules/ioredis/built/redis/event_handler.js:156:20)
at Object.onceWrapper (node:events:622:26)
at Socket.emit (node:events:507:28)
at TCP.<anonymous> (node:net:346:12)
Version
ioredis 5.8.0
Context
We have code for a health check that connects and immediately disconnects using await ioredis.quit().
The issue occurs often since #2011. I assume the reason for this is, that we now have entries on the commandQueue immediately.
Workaround
The issue does not occur anymore when I set disableClientInfo to true.
Reason
Usually the commandQueue is empty and the connection terminates sucessfully. However, when the error occures, we have the following entries on the commandQueue
[
{
command: Command {
name: 'client',
inTransaction: false,
isResolved: false,
transformed: true,
replyEncoding: 'utf8',
errorStack: undefined,
args: [Array],
callback: undefined,
resolve: [Function (anonymous)],
reject: [Function (anonymous)],
promise: [Promise]
},
stream: undefined,
select: 0
},
{
command: Command {
name: 'quit',
inTransaction: false,
isResolved: false,
transformed: true,
replyEncoding: 'utf8',
errorStack: undefined,
args: [],
callback: undefined,
resolve: [Function (anonymous)],
reject: [Function (anonymous)],
promise: [Promise]
},
stream: undefined,
select: 0
}
]
The closeHandler flushes the queue with an error (
ioredis/lib/redis/event_handler.ts
Line 227 in 8dad79f
| self.flushQueue(new Error(CONNECTION_CLOSED_ERROR_MSG)); |
Thus,
quit can only ever complete successfully if the queue is empty.