-
Notifications
You must be signed in to change notification settings - Fork 580
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 Semaphore Disposed Exception in AsyncConsumerWorkService #1015
Fix Semaphore Disposed Exception in AsyncConsumerWorkService #1015
Conversation
@ashneilson Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@ashneilson Thank you for signing the Contributor License Agreement! |
- Refers to the Exception thrown in this PR: rabbitmq/rabbitmq-dotnet-client#1015
Thank you! |
…ispose Fix Semaphore Disposed Exception in AsyncConsumerWorkService (cherry picked from commit cff0c3d)
Backported to |
Hmm probably irrelevant but now the remaining work items won't be processed. (kind of also didn't before due to the dispose exception), but what would we expect here? Shouldn't all the items be processed? |
Thanks for raising this point @bollhals. The behavior is still as before given the rabbitmq-dotnet-client/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs Lines 185 to 191 in cff0c3d
Under typical circumstances, an rabbitmq-dotnet-client/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs Lines 125 to 147 in cff0c3d
One would assume that if the processing of work items (e.g. |
Publisher confirms have no effect on the redelivery behaviour or consumer acknowledgements. It would be nice to process the backlog of work items that were already submitted, in case anyone has more cycles to spend improving this client :) |
#997 does it. |
But we could also consider a change to it so that on close it waits but on abort it does not. |
Sorry @michaelklishin! Thanks for correcting me. I had meant to suggest with AutoAck disabled, using a A simple solution could be to rabbitmq-dotnet-client/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs Lines 185 to 191 in cff0c3d
I noted that during Connection Recovery, this WorkService is destroyed and re-created. Would we still want to process the backlog given this could delay recovery quite significantly? |
Proposed Changes
Fixes a
System.ObjectDisposedException
thrown when theSemaphoreSlim
is Disposed on aAsyncConsumerWorkService
with a Concurrency greater than 1.Current State
When under load, the ChannelReader can return a Work item after the
_limiter
has been Disposed resulting in the Exception being thrown.rabbitmq-dotnet-client/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs
Lines 131 to 139 in d39bb71
Proposed Fix
We check if the
cancellationToken
has been cancelled. If so, we avoid attempting to wait on the_limiter
and will not see an Exception thrown.https://github.com/ricado-group/rabbitmq-dotnet-client/blob/08854f1a83b3c4a1214f41518bbfa380ec673e1c/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs#L130-L139
Types of Changes
Checklist
CONTRIBUTING.md
document