-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fix lock and semaphore timeouts #64
Conversation
}; | ||
|
||
var attempts = 0; | ||
var start = DateTime.UtcNow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTime
arithmetic is not a good way of calculating elapsed time, StopWatch
is more accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, @marcin-krystianc!
I just have one tiny nitpick below, but otherwise it LGTM 👍
Consul/Lock.cs
Outdated
@@ -251,23 +252,24 @@ public async Task<CancellationToken> Acquire(CancellationToken ct) | |||
|
|||
var qOpts = new QueryOptions() | |||
{ | |||
WaitTime = Opts.LockWaitTime | |||
WaitTime = Opts.LockWaitTime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the comma at the end for style consistency with the rest of the project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
A more in depth explanation of @marcin-krystianc's fix can be found in the original PR for Consul. |
…marcink-20210121-lock-fix
Consul/Lock.cs
Outdated
{ | ||
DisposeCancellationTokenSource(); | ||
throw new LockMaxAttemptsReachedException("LockTryOnce is set and the lock is already held or lock delay is in effect"); | ||
} | ||
qOpts.WaitTime -= elapsed; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the extra line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
The logic for calculating the
WaitTime
was broken.I think that this bug was inherited from go library. It is fixed there already (hashicorp/consul@9043966)