use random string tokens in LuaLock #411
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this pull request is based on #405 from @natict addressing the issues from comments. since it looks like he hasn't had time to respond to those comments, i made changes based on his implementation; apologies to the community if doing this is frowned upon or if there's a better way (his changeset is in this pull request, so merging this would obviate #405). i saw the comment in #408 saying #405 would get merged in, but i haven't seen a commit for that yet, feel free to close this if you're already done.
the main thing this patch changes from @natict's implementation is to store a random token rather than the floating point value of the client machine's clock in string form, as
Lockcurrently does. one invariant goes away as a side effect - after a release,tokenin theLuaLockinstance keeps its previous value, rather than being set toNoneasLockdoes toacquired_until. i couldn't find a good way to keep that behavior since the script is effectively atomic - adding a pipeline torelease()would probably work, but i chose to keep the code simple for now.feedback welcome on everything, but i'd specifically like comments about the
redis.client.generate_random_token()function - there may be better/more desirable ways to do this.i didn't touch any of the context manager stuff, so the changes in #408 would need to be duplicated in LuaLock.
each lock implementation has its own test suite now, and both are always run. i didn't do anything special if the redis server being used is pre-2.6 -
LuaLocktests will always fail in that case. i'm not sure what you target for automated tests, so this may need some touchups.for both
LockandLuaLock, it appears to be possible to incorrectly release a lock that has a timeout when sharing a lock instance within a single process. i need to set up a test case to confirm this, and if it does happen, i'll open a separate issue to propose a solution.