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 issue where SemaphoreSlim is released twice in RateLimitGate #210

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

Jonnern
Copy link
Contributor

@Jonnern Jonnern commented Aug 27, 2024

CheckGuardsAsync releases the semaphore when a request is rate-limited. If this task is canceled, the caller ProcessAsync, will also release the semaphore in the finally block. After this point, the RateLimiter is no longer thread-safe.

The implementation assumes that CheckGuardsAsync cannot throw a TaskCanceledException before the semaphore has been released.

@JKorf
Copy link
Owner

JKorf commented Aug 28, 2024

Hi, I had to look for a bit but you're right, good find!
Could you also add it to the ProcessSingleAsync method?

@Jonnern Jonnern force-pushed the bug/double-release-semaphore branch from 318fb03 to 5699809 Compare August 28, 2024 10:22
@Jonnern
Copy link
Contributor Author

Jonnern commented Aug 28, 2024

I updated ProcessSingleAsync as well and squashed the commits

@JKorf JKorf merged commit 42003a0 into JKorf:master Aug 28, 2024
1 check passed
@Jonnern Jonnern deleted the bug/double-release-semaphore branch August 28, 2024 10:33
@Jonnern
Copy link
Contributor Author

Jonnern commented Aug 28, 2024

@JKorf Would it be better to return
return new CallResult(new CancellationRequestedError()); in the catch block than rethrow?

@JKorf
Copy link
Owner

JKorf commented Aug 28, 2024

Look at it now, I think you're right. If you cancel the wait then I think the exception isn't actually caught anywhere. I'll fix that with the new release

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