From 4d1be7762c644a0156cc4e1ca9927462d912c3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Fri, 10 Dec 2021 20:14:15 -0500 Subject: [PATCH 1/2] fix(connection): throw error when invalid redis options are provided check invalid redis option params BREAKING CHANGE: throw error when maxRetriesPerRequest or enableReadyCheck provided --- src/classes/redis-connection.ts | 15 ++++++--------- tests/test_connection.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/classes/redis-connection.ts b/src/classes/redis-connection.ts index 34e235facc..2615cdc13f 100644 --- a/src/classes/redis-connection.ts +++ b/src/classes/redis-connection.ts @@ -12,13 +12,11 @@ import * as path from 'path'; const overrideMessage = [ 'BullMQ: WARNING! Your redis options maxRetriesPerRequest must be null and enableReadyCheck false', - 'and will be overrided by BullMQ.', + 'and will be overridden by BullMQ.', ].join(' '); -const deprecationMessage = [ - 'BullMQ: DEPRECATION WARNING! Your redis options maxRetriesPerRequest must be null and enableReadyCheck false.', - 'On the next versions having this settings will throw an exception', -].join(' '); +const connectionErrorMessage = `Using a redis instance with enableReadyCheck or maxRetriesPerRequest is not permitted. +See https://https://github.com/OptimalBits/bull/issues/1873`; export class RedisConnection extends EventEmitter { static minimumVersion = '5.0.0'; @@ -50,12 +48,11 @@ export class RedisConnection extends EventEmitter { }; } else { this._client = opts; - this.checkOptions(deprecationMessage, this._client.options); if ( - (opts).maxRetriesPerRequest || - (opts).enableReadyCheck + (this._client.options).maxRetriesPerRequest || + this._client.options.enableReadyCheck ) { - console.error(deprecationMessage); + throw new Error(connectionErrorMessage); } } diff --git a/tests/test_connection.ts b/tests/test_connection.ts index bdc24b644d..30c390adbe 100644 --- a/tests/test_connection.ts +++ b/tests/test_connection.ts @@ -42,6 +42,32 @@ describe('connection', () => { checkOptions(await queue.client); }); + describe('when reusing connection with enableReadyCheck as true', () => { + it('throws an error', async () => { + const connection = new IORedis({ + maxRetriesPerRequest: null, + enableReadyCheck: true, + }); + + expect(() => new QueueBase(queueName, { connection })).to + .throw(`Using a redis instance with enableReadyCheck or maxRetriesPerRequest is not permitted. +See https://https://github.com/OptimalBits/bull/issues/1873`); + }); + }); + + describe('when reusing connection with maxRetriesPerRequest different than null', () => { + it('throws an error', async () => { + const connection = new IORedis({ + maxRetriesPerRequest: 1, + enableReadyCheck: false, + }); + + expect(() => new QueueBase(queueName, { connection })).to + .throw(`Using a redis instance with enableReadyCheck or maxRetriesPerRequest is not permitted. +See https://https://github.com/OptimalBits/bull/issues/1873`); + }); + }); + describe('when maxmemory-policy is different than noeviction in Redis', () => { it('throws an error', async () => { const opts = { From d7da65894574f3006cd5c7be23cb43eef71c4f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Fri, 10 Dec 2021 20:25:58 -0500 Subject: [PATCH 2/2] test: fix test case --- tests/test_worker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_worker.ts b/tests/test_worker.ts index 59e23a212f..260ce770c1 100644 --- a/tests/test_worker.ts +++ b/tests/test_worker.ts @@ -654,7 +654,10 @@ describe('workers', function () { describe('when sharing a redis connection between workers', function () { it('should not close the connection', async () => { - const connection = new IORedis(); + const connection = new IORedis({ + maxRetriesPerRequest: null, + enableReadyCheck: false, + }); return new Promise((resolve, reject) => { connection.on('ready', async () => {