Skip to content

Commit bceb40a

Browse files
author
Petros Argyrakis
committed
fix modelshutown corner case
fix commit cff0c3d did solve the semaphore disposed exception, however, there is a bug that prevents the modelshutdown work from being exectuted and the registered handler from being called.
1 parent 23d2101 commit bceb40a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private async Task LoopWithConcurrency(CancellationToken cancellationToken)
128128
{
129129
while (await _channel.Reader.WaitToReadAsync(cancellationToken).ConfigureAwait(false))
130130
{
131-
while (_channel.Reader.TryRead(out Work work) && !cancellationToken.IsCancellationRequested)
131+
while (_channel.Reader.TryRead(out Work work))
132132
{
133133
// Do a quick synchronous check before we resort to async/await with the state-machine overhead.
134134
if (!_limiter.Wait(0))
@@ -144,6 +144,10 @@ private async Task LoopWithConcurrency(CancellationToken cancellationToken)
144144
{
145145
// ignored
146146
}
147+
finally
148+
{
149+
_limiter?.Dispose();
150+
}
147151
}
148152

149153
private static async Task HandleConcurrent(Work work, IModel model, SemaphoreSlim limiter)
@@ -186,7 +190,6 @@ public Task Stop()
186190
{
187191
_channel.Writer.Complete();
188192
_tokenSource?.Cancel();
189-
_limiter?.Dispose();
190193
return _worker;
191194
}
192195
}

0 commit comments

Comments
 (0)