-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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.Lock() returns without the lock way before LockWaitTime #4003
Comments
Am running into this as well using I think your fix works in that it will stop the I'm not sure what the correct behaviour is here. Suspect this is why |
@benagricola the documentation for LockWaitTime (at least in code) points out that it is a tradeoff that affects how soon you might return if lock is not acquired. Note that the timeout specified is used as the I think the wait time decrementing was just a bug with no tests to catch it not an intentional way to mitigate the fact that you can't separate the individual blocking request time (and hence max delay before returning) and the actual time the lock attempt will block for. The fix in the PR should make this behaviour work correctly though - the last blocking query when there is less than 10 mins of timeout left will subtract elapsed from 8hrs and get back the smaller wait time required to unblock right at the 8hr elapsed mark. |
Description of the Issue (and unexpected/desired result)
Using the lock api with these LockOptions :
would expect that a call to lock.Lock(nil) would attempt to acquire the lock for 45 seconds before returning without having succeeded.
But actually, in a multi-threaded environment where many threads attempted to acquire the lock, after 5 seconds many of them could get the lock but several threads saw lock.Lock(nil) return nil,nil.
Although only 5 seconds had passed, and the LockWaitTime specified was 45 seconds.
Looking at the code, in the following lines
at https://github.com/hashicorp/consul/blob/v1.0.6/api/lock.go#L181-L189
Line 184, the elapsed time since start is compared to qOpts.WaitTime, which seems correct.
But the issue is that line 188, qOpts.WaitTime is lowered by substracting the elapsed time.
Let's say the elapsed time since start is around 5 seconds, after each attempt which can be quick,
you will substract around 5 seconds to qOpts.WaitTime.
So elapsed time will be > qOpts.WaitTime way sooner than expected.
I think a fix should be to replace line 184 :
by :
to compare the elapsed time with the LockWaitTime provided by the user.
consul version
for both Client and ServerUsing the latest version 1.0.6
The text was updated successfully, but these errors were encountered: