@@ -184,8 +184,10 @@ private void HandleAck(ulong deliveryTag, bool multiple)
184
184
{
185
185
if ( pair . Key <= deliveryTag )
186
186
{
187
- pair . Value . SetResult ( true ) ;
188
- _confirmsTaskCompletionSources . Remove ( pair . Key , out _ ) ;
187
+ if ( _confirmsTaskCompletionSources . TryRemove ( pair . Key , out TaskCompletionSource < bool > ? tcs ) )
188
+ {
189
+ tcs . SetResult ( true ) ;
190
+ }
189
191
}
190
192
}
191
193
}
@@ -210,14 +212,16 @@ private void HandleNack(ulong deliveryTag, bool multiple, bool isReturn)
210
212
{
211
213
if ( pair . Key <= deliveryTag )
212
214
{
213
- pair . Value . SetException ( new PublishException ( pair . Key , isReturn ) ) ;
214
- _confirmsTaskCompletionSources . Remove ( pair . Key , out _ ) ;
215
+ if ( _confirmsTaskCompletionSources . TryRemove ( pair . Key , out TaskCompletionSource < bool > ? tcs ) )
216
+ {
217
+ tcs . SetException ( new PublishException ( pair . Key , isReturn ) ) ;
218
+ }
215
219
}
216
220
}
217
221
}
218
222
else
219
223
{
220
- if ( _confirmsTaskCompletionSources . Remove ( deliveryTag , out TaskCompletionSource < bool > ? tcs ) )
224
+ if ( _confirmsTaskCompletionSources . TryRemove ( deliveryTag , out TaskCompletionSource < bool > ? tcs ) )
221
225
{
222
226
tcs . SetException ( new PublishException ( deliveryTag , isReturn ) ) ;
223
227
}
@@ -382,7 +386,7 @@ await publisherConfirmationInfo.MaybeWaitForConfirmationAsync(cancellationToken)
382
386
}
383
387
catch ( OperationCanceledException )
384
388
{
385
- _confirmsTaskCompletionSources . Remove ( publisherConfirmationInfo . PublishSequenceNumber , out _ ) ;
389
+ _confirmsTaskCompletionSources . TryRemove ( publisherConfirmationInfo . PublishSequenceNumber , out _ ) ;
386
390
throw ;
387
391
}
388
392
finally
0 commit comments