Skip to content

Commit 1bc26a6

Browse files
authoredFeb 16, 2024··
fix(redis-connection): close redis connection even when initializing (#2425) fixes #2385
1 parent d08cd59 commit 1bc26a6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎src/classes/redis-connection.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,21 @@ export class RedisConnection extends EventEmitter {
288288
const status = this.status;
289289
this.status = 'closing';
290290
this.closing = true;
291+
291292
try {
292293
if (status === 'ready') {
293294
// Not sure if we need to wait for this
294295
await this.initializing;
295-
if (!this.shared) {
296+
}
297+
if (!this.shared) {
298+
if (status == 'initializing') {
299+
// If we have not still connected to Redis, we need to disconnect.
300+
this._client.disconnect();
301+
} else {
296302
await this._client.quit();
297303
}
304+
// As IORedis does not update this status properly, we do it ourselves.
305+
this._client['status'] = 'end';
298306
}
299307
} catch (error) {
300308
if (isNotConnectionError(error as Error)) {

‎tests/test_connection.ts

+14
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ describe('connection', () => {
144144
await worker.close();
145145
});
146146

147+
it('should close underlying redis connection when closing fast', async () => {
148+
const queue = new Queue('CALLS_JOB_QUEUE_NAME', {
149+
connection: {
150+
host: 'localhost',
151+
port: 6379,
152+
},
153+
});
154+
155+
const client = queue['connection']['_client'];
156+
await queue.close();
157+
158+
expect(client.status).to.be.eql('end');
159+
});
160+
147161
it('should recover from a connection loss', async () => {
148162
let processor;
149163

0 commit comments

Comments
 (0)
Please sign in to comment.