node-redlock: Unable to lock multi resources in cluster mode

node-relock version: 4.1.0 ioredis version: 4.14.1

Hi, I’m trying to use node-redlock with redis-cluster. When locking multi resources, I got a “LockError” exception. It exceeds the 10 attempts to lock.

Here’s my code

  let client = new redis.Cluster([
        {
            ip: '127.0.0.1',
            port: '7001'
        },
        {
            ip: '127.0.0.1',
            port: '7002'
        },
        {
            ip: '127.0.0.1',
            port: '7003'
        }
    ])
    let lk = new redlock([client])
    let l = null
    l = await lk.lock(['lk1', 'lk2'], 1000) //failure
    //l = await lk.lock(['lk'], 1000)  //success
    let res = await client.get('foo')
(node:28707) UnhandledPromiseRejectionWarning: LockError: Exceeded 10 attempts to lock the resource "lk1,lk2".
    at /home/sx/projects/nodejs/njproj1/node_modules/redlock/redlock.js:411:20
    at tryCatcher (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/util.js:16:23)
    at Promise.errorAdapter [as _rejectionHandler0] (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/nodeify.js:35:34)
    at Promise._settlePromise (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/promise.js:601:21)
    at Promise._settlePromise0 (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues (/home/sx/projects/nodejs/njproj1/node_modules/bluebird/js/release/async.js:15:14)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

@RuoFeng2015 @shonmorgun . I faced the same issue and going through the documentation revealed that the lock can only be applied to keys which have not been set yet. If you are trying to lock a key which is already redis db, then the lock execution will always fail. Try to run the same code with a new key.

You can find the info in attached screenshot on documentation for 4.2.0 on npmjs Screenshot 2022-02-15 at 1 54 12 PM

This is still an issue guys

hi guys, i have find the way to solve this problem. if fact , this error occur when the retry time access the max times in the init config. the source code is

if (attempts.length < maxAttempts) {
                await new Promise((resolve) => {
                    setTimeout(resolve, Math.max(0, settings.retryDelay +
                        Math.floor((Math.random() * 2 - 1) * settings.retryJitter)), undefined);
                });
            }
            else {
                throw new ExecutionError("The operation was unable to achieve a quorum during its retry window.", attempts);
            }

so I config the retryCount to 20 and retryDelay to 2000ms. in most of case , it did well

Hi folks! I’m going to go ahead and close this, as I just published v5.0.0-beta.1 which includes extensive cluster tests and some small improvements over the v5 alpha that should aid in debugging.

@richard-julien consider adopting using following to extract the underlying issues from an ExecutionError:

https://github.com/mike-marcacci/node-redlock/blob/078c7270a48596db8a23b4884f88db1f1eb3c18b/src/single.test.ts#L14-L31