-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to lock multi resources in cluster mode #64
Comments
Hi @mike-marcacci , Just tested this use case with the 5.0-alpha on a redis cluster (using https://github.com/bitnami/bitnami-docker-redis-cluster) with the exact same problem. Does it require to configure something specific? Thanks in advance SUCCESS: redlock.using(['id1'], maxTtl, async (signal) => {}) FAILURE: redlock.using(['id1', 'id2'], maxTtl, async (signal) => {})
|
Hi folks! I'm going to go ahead and close this, as I just published @richard-julien consider adopting using following to extract the underlying issues from an node-redlock/src/single.test.ts Lines 14 to 31 in 078c727
|
Issue still is a thing in |
Thanks for that confirmation @nickreynke. Reopening this issue to continue tracking. When adding cluster tests I realized that there was some nuance around hash slots and added some additional notes about use with cluster/sentinel setups to the readme. Could you look over those and see if they solve your problem? |
the problem is still here redlock v5.0.0-beta.1 `
`
|
Hi @mike-marcacci, same issue with node version: v16.13.1 package.json Here is my code const { default: Redlock } = require("redlock");
const Client = require('ioredis');
const client = new Client();
const redlock = new Redlock(
[client],
{
driftFactor: 0.01,
retryCount: 5,
retryDelay: 1000,
retryJitter: 1000
}
);
redlock.on('clientError', function(err) {
console.error('A redis error has occurred:', err);
});
const sleep = (time) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, time)
});
}
const main = async (key) => {
const lock = await redlock.acquire([key], 6000);
try {
console.log(new Date(), 'client1 do something');
await sleep(1000);
console.log(new Date(), 'client1 do something else');
await sleep(2000);
} catch (err) {
console.log(err);
} finally {
await lock.release();
console.log(new Date(), 'client1 release lock');
}
}
main('key');
main('key');
main('key'); Error info:
|
I try to use |
出现了同样的问题 The operation was unable to acheive a quorum during |
This is still an issue guys |
@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 |
hi guys, i have find the way to solve this problem. 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. |
Hey guys. I was able to workaround this issue by running my instance in WSL (Windows Subsystem for Linux). I haven't figured out why redlock is not working on Windows but it will work on Linux, and WSL. Best of luck! |
Hey there! I faced the same issue on Windows and solved it after updating ioredis to v5.0.4. Ps: Also make sure don't use redis lib instead of ioredis. |
Hey there! I finally found the root cause of this error: Cheers! |
Hi folks, something new about "The operation was unable to achieve a quorum during its retry window" ? I have the same problem using: |
We are also facing the issue, we are using the aws elasticcache (redis) service with a 1 repli - primary setup. the primary didn't switch during the issues, so I guess this is unrelated. Maybe relevant: the unlock/release of the lock also fails sometimes? |
same problem |
Does anyone have solutions to fix it? I'm using the latest version of 2 packages redlock ("5.0.0-beta.2") and ioredis ("5.4.1") to connect with Redis sentinels ("7.4.0"). Please help me if you know any way to fix this. I tried using version 4.5.2 before to connect with Redis Sentinels, but it did not work well. |
Hi @mike-marcacci My deadline is coming up soon, and I need your help. 🥲 |
@AJackTi import Redlock from 'redlock'
import { redis } from '../storage/redis'
export const redlock = new Redlock([redis], {
// The expected clock drift; for more details see:
// http://redis.io/topics/distlock
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
// The max number of times Redlock will attempt to lock a resource
// before erroring.
retryCount: 30,
// the time in ms between attempts
retryDelay: 2000, // time in ms
// the max time in ms randomly added to retries
// to improve performance under high contention
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
retryJitter: 200, // time in ms
// The minimum remaining time on a lock before an extension is automatically
// attempted with the `using` API.
automaticExtensionThreshold: 500, // time in ms
})
// Save the original acquire method
const originalAcquire = Redlock.prototype.acquire
// Override the release method for all lock instances
Redlock.prototype.acquire = async function (...args) {
const duration = args[1] // this is a duration value
// use the duration to create additional settings
args[2] = {
retryCount: Math.ceil((duration / 2_000) * 1.5),
retryDelay: 2_000,
...args[2],
}
return originalAcquire.apply(this, args) // Call the original release method
}
// Save the original release method
const originalRelease = Redlock.prototype.release
// Override the release method for all lock instances
Redlock.prototype.release = async function (...args) {
const now = new Date().getTime()
if (args[0] && args[0].expiration > now) {
// Check if the lock still exists
return originalRelease.apply(this, args) // Call the original release method
}
return {
attempts: [],
}
} |
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
The text was updated successfully, but these errors were encountered: