-
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
Lock in use should throw a specific error #288
Comments
My workaround is to used the error attempts returned in the catch,
|
This cannot truly lock the key |
@slavafomin @JohnWilliamForcier-Spiria 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: [],
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
Consider the following code:
It tries to acquire the same lock two times: the first time successful and the second time with error (which is expected). However, the error that is thrown is:
ExecutionError: The operation was unable to achieve a quorum during its retry window.
. I'm not sure about the quorum, but shouldn't theResourceLockedError
be thrown instead?Also, what
retryCount
andretryDelay
parameters are used for exactly? Are they used for multiple tries when acquiring a quorum or are they also used while waiting for existing lock to release?Thank you.
The text was updated successfully, but these errors were encountered: