From 95252a495adc2793b5e2c3933d8002164fb79ce4 Mon Sep 17 00:00:00 2001 From: roggervalf Date: Thu, 14 Mar 2024 23:42:41 -0500 Subject: [PATCH 1/3] fix(connection): console connection closed error instead of throw an actual error --- src/classes/redis-connection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/classes/redis-connection.ts b/src/classes/redis-connection.ts index 3247b5fce1..f8e7362121 100644 --- a/src/classes/redis-connection.ts +++ b/src/classes/redis-connection.ts @@ -162,7 +162,8 @@ export class RedisConnection extends EventEmitter { }; handleEnd = () => { - reject(lastError || new Error(CONNECTION_CLOSED_ERROR_MSG)); + console.error(lastError?.message || CONNECTION_CLOSED_ERROR_MSG); + resolve(); }; increaseMaxListeners(client, 3); From 5915b9e230ed49d25c575c26868789e1a1e66252 Mon Sep 17 00:00:00 2001 From: roggervalf Date: Tue, 2 Apr 2024 22:31:15 -0500 Subject: [PATCH 2/3] fix: ignore error when after we set our custom client status --- src/classes/redis-connection.ts | 59 ++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/classes/redis-connection.ts b/src/classes/redis-connection.ts index f8e7362121..8eb9b13651 100644 --- a/src/classes/redis-connection.ts +++ b/src/classes/redis-connection.ts @@ -162,8 +162,12 @@ export class RedisConnection extends EventEmitter { }; handleEnd = () => { - console.error(lastError?.message || CONNECTION_CLOSED_ERROR_MSG); - resolve(); + if (client.status !== 'end') { + reject(lastError || new Error(CONNECTION_CLOSED_ERROR_MSG)); + } else { + // when custon 'end' status is set we already closed + resolve(); + } }; increaseMaxListeners(client, 3); @@ -216,34 +220,37 @@ export class RedisConnection extends EventEmitter { this.loadCommands(); - this.version = await this.getRedisVersion(); - if (this.skipVersionCheck !== true && !this.closing) { - if ( - isRedisVersionLowerThan(this.version, RedisConnection.minimumVersion) - ) { - throw new Error( - `Redis version needs to be greater or equal than ${RedisConnection.minimumVersion} Current: ${this.version}`, - ); - } + if (this._client['status'] !== 'end') { + this.version = await this.getRedisVersion(); + if (this.skipVersionCheck !== true && !this.closing) { + if ( + isRedisVersionLowerThan(this.version, RedisConnection.minimumVersion) + ) { + throw new Error( + `Redis version needs to be greater or equal than ${RedisConnection.minimumVersion} ` + + `Current: ${this.version}`, + ); + } - if ( - isRedisVersionLowerThan( - this.version, - RedisConnection.recommendedMinimumVersion, - ) - ) { - console.warn( - `It is highly recommended to use a minimum Redis version of ${RedisConnection.recommendedMinimumVersion} - Current: ${this.version}`, - ); + if ( + isRedisVersionLowerThan( + this.version, + RedisConnection.recommendedMinimumVersion, + ) + ) { + console.warn( + `It is highly recommended to use a minimum Redis version of ${RedisConnection.recommendedMinimumVersion} + Current: ${this.version}`, + ); + } } - } - this.capabilities = { - canDoubleTimeout: !isRedisVersionLowerThan(this.version, '6.0.0'), - }; + this.capabilities = { + canDoubleTimeout: !isRedisVersionLowerThan(this.version, '6.0.0'), + }; - this.status = 'ready'; + this.status = 'ready'; + } return this._client; } From 602054357275ef5fc8d29ce94c10c5d8e3f5b4e0 Mon Sep 17 00:00:00 2001 From: roggervalf Date: Tue, 2 Apr 2024 22:37:43 -0500 Subject: [PATCH 3/3] chore: reject if there is a last error --- src/classes/redis-connection.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/classes/redis-connection.ts b/src/classes/redis-connection.ts index 8eb9b13651..3e752828c8 100644 --- a/src/classes/redis-connection.ts +++ b/src/classes/redis-connection.ts @@ -165,8 +165,12 @@ export class RedisConnection extends EventEmitter { if (client.status !== 'end') { reject(lastError || new Error(CONNECTION_CLOSED_ERROR_MSG)); } else { - // when custon 'end' status is set we already closed - resolve(); + if (lastError) { + reject(lastError); + } else { + // when custon 'end' status is set we already closed + resolve(); + } } };