Skip to content

Commit c48822c

Browse files
committed
Fix very rare deadlock
Fixes #1751 Attempt to fix deadlock by waiting on channel dispatcher first, then channel reader.
1 parent 75822ae commit c48822c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

projects/RabbitMQ.Client/ConsumerDispatching/ConsumerDispatcherChannelBase.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,17 @@ public async Task WaitForShutdownAsync()
161161
{
162162
try
163163
{
164-
await _reader.Completion
165-
.ConfigureAwait(false);
166164
await _worker
167165
.ConfigureAwait(false);
166+
167+
/*
168+
* rabbitmq/rabbitmq-dotnet-client#1751
169+
*
170+
* Wait for the worker first to ensure all items have been read out of the channel,
171+
* otherwise the following will never return (https://stackoverflow.com/a/66521303)
172+
*/
173+
await _reader.Completion
174+
.ConfigureAwait(false);
168175
}
169176
catch (AggregateException aex)
170177
{

0 commit comments

Comments
 (0)