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

Lock.release(): reorder code to avoid token overwrite #489

Merged
merged 1 commit into from
Jun 5, 2014

Conversation

chillipino
Copy link
Contributor

the recent lock rewrite reintroduced a data stomp bug similar to the one fixed in #384. this change should patch the problem for locks that do not have timeouts, which is the same behavior the library had pre-rewrite. here is a gist demonstrating the issue. before applying this change, i was able to get double-release exceptions about 50% of the time on a linux VM with a sleepTime of 0.15s, and 100% of the time on windows with a sleepTime of 0.1s. i did all of the above tests with python 2.7.5.

unfortunately, the bug described in #416 is still present, which is closely related to this code. i'll open a separate issue for that.

* assignment to self.token was not protected by the lock, so the value could get overwritten
* do_release() now has an expected_token parameter that receives the old token value
* NOTE: this only fixes the issue for locks that do not have timeouts
andymccurdy added a commit that referenced this pull request Jun 5, 2014
Lock.release(): reorder code to avoid token overwrite
@andymccurdy andymccurdy merged commit d6fc144 into redis:master Jun 5, 2014
@andymccurdy
Copy link
Contributor

Ah, ya that makes sense. I hadn't spent much time thinking about the use cases where multiple Python threads used a shared lock instance.

Let me know what you come up with about the timeout issue.

@andymccurdy
Copy link
Contributor

Just re-read #416. I see what you're talking about now -- when thread-0 calls release() after running over the timeout it uses the token that thread-1 (who now holds the lock) generated.

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

Successfully merging this pull request may close these issues.

2 participants