Skip to content
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

When refreshing the lock, should check whether the lock is held. #55

Open
brodyxchen opened this issue Nov 6, 2023 · 0 comments
Open

Comments

@brodyxchen
Copy link

brodyxchen commented Nov 6, 2023

Hello, I am looking a HA solution for celery beat and found this project, Thanks for you project, It is useful to me.

But When I learn the code, I found one possible problem about how to refreshing/extending the lock.

There could check lock before extended lock, so should use a lua script do check lock and extend lock, this ensures atomicity.

Finally, we also need to check the result of the refresh/extend lock, it is possible that the refresh/extend failed, meaning missing lock or network error.


Like this: (from redbeat)
https://github.com/sibson/redbeat/blob/5d1d5c154d2e080d3135afee235321abf5d2da5b/redbeat/schedulers.py#L37

    local token = redis.call('get', KEYS[1])
    if not token or token ~= ARGV[1] then
        return 0
    end
    local expiration = redis.call('pttl', KEYS[1])
    if not expiration then
        expiration = 0
    end
    if expiration < 0 then
        return 0
    end
    redis.call('pexpire', KEYS[1], ARGV[2])
    return 1

or Like this: (from golang redlock lib)
https://github.com/go-redsync/redsync/blob/311e82d385dcf0b228cb1b4974b690f8bb2dc127/mutex.go#L254

	if redis.call("GET", KEYS[1]) == ARGV[1] then
		return redis.call("PEXPIRE", KEYS[1], ARGV[2])
	else
		return 0
	end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant