Skip to content

Commit

Permalink
fix(redis-connection): close redis connection even when initializing (#…
Browse files Browse the repository at this point in the history
…2425) fixes #2385
  • Loading branch information
manast authored Feb 16, 2024
1 parent d08cd59 commit 1bc26a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,21 @@ export class RedisConnection extends EventEmitter {
const status = this.status;
this.status = 'closing';
this.closing = true;

try {
if (status === 'ready') {
// Not sure if we need to wait for this
await this.initializing;
if (!this.shared) {
}
if (!this.shared) {
if (status == 'initializing') {
// If we have not still connected to Redis, we need to disconnect.
this._client.disconnect();
} else {
await this._client.quit();
}
// As IORedis does not update this status properly, we do it ourselves.
this._client['status'] = 'end';
}
} catch (error) {
if (isNotConnectionError(error as Error)) {
Expand Down
14 changes: 14 additions & 0 deletions tests/test_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ describe('connection', () => {
await worker.close();
});

it('should close underlying redis connection when closing fast', async () => {
const queue = new Queue('CALLS_JOB_QUEUE_NAME', {
connection: {
host: 'localhost',
port: 6379,
},
});

const client = queue['connection']['_client'];
await queue.close();

expect(client.status).to.be.eql('end');
});

it('should recover from a connection loss', async () => {
let processor;

Expand Down

0 comments on commit 1bc26a6

Please sign in to comment.