From cc0c0de45644c383f090eda25ff43a387de745ad Mon Sep 17 00:00:00 2001 From: lopaz <8480947+lopaz@users.noreply.github.com> Date: Sun, 13 Aug 2023 02:06:01 +0800 Subject: [PATCH] Failure of transaction with watch should be ignored. (#977) The method `Scheduler.cleanupTimestamp` uses Optimistic locking by watch command, it's quite possible some watched keys changed during transaction (as a result, null is returned), it's OK, scheduler will start next polling, and the failed timestamp will be retried. ref: https://redis.io/docs/interact/transactions/#optimistic-locking-using-check-and-set --- src/core/scheduler.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/scheduler.ts b/src/core/scheduler.ts index cd822bd5..ae898c6b 100644 --- a/src/core/scheduler.ts +++ b/src/core/scheduler.ts @@ -259,12 +259,13 @@ export class Scheduler extends EventEmitter { .del(key) .zrem(this.connection.key("delayed_queue_schedule"), timestamp) .exec(); - - response.forEach((res) => { - if (res[0] !== null) { - throw res[0]; - } - }); + if (response !== null) { + response.forEach((res) => { + if (res[0] !== null) { + throw res[0]; + } + }); + } } await this.unwatchIfPossible(); }