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

Fix lock and semaphore timeouts #64

Merged
merged 5 commits into from
Jan 22, 2021
Merged

Conversation

marcin-krystianc
Copy link
Contributor

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)

};

var attempts = 0;
var start = DateTime.UtcNow;
Copy link
Contributor Author

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.

Copy link
Member

@jgiannuzzi jgiannuzzi left a 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,
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jgiannuzzi
Copy link
Member

A more in depth explanation of @marcin-krystianc's fix can be found in the original PR for Consul.

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;

Copy link
Member

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?

Copy link
Member

@jgiannuzzi jgiannuzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@marcin-krystianc marcin-krystianc merged commit d688220 into master Jan 22, 2021
@marcin-krystianc marcin-krystianc deleted the marcink-20210121-lock-fix branch January 22, 2021 07:32
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