Skip to content

Commit

Permalink
Maxing sure continuations are consistently disposed because they tend…
Browse files Browse the repository at this point in the history
… to create timer based cancellation token sources and linked tokens
  • Loading branch information
danielmarbach authored and lukebakken committed Dec 7, 2024
1 parent 6670384 commit 36ac973
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 187 deletions.
37 changes: 13 additions & 24 deletions projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,38 +131,27 @@ private async Task MaybeConfirmSelect(CancellationToken cancellationToken)
if (_publisherConfirmationsEnabled)
{
// NOTE: _rpcSemaphore is held
bool enqueued = false;
var k = new ConfirmSelectAsyncRpcContinuation(ContinuationTimeout, cancellationToken);
using var k = new ConfirmSelectAsyncRpcContinuation(ContinuationTimeout, cancellationToken);

try
if (_nextPublishSeqNo == 0UL)
{
if (_nextPublishSeqNo == 0UL)
if (_publisherConfirmationTrackingEnabled)
{
if (_publisherConfirmationTrackingEnabled)
{
_confirmsTaskCompletionSources.Clear();
}
_nextPublishSeqNo = 1;
_confirmsTaskCompletionSources.Clear();
}
_nextPublishSeqNo = 1;
}

enqueued = Enqueue(k);
Enqueue(k);

var method = new ConfirmSelect(false);
await ModelSendAsync(in method, k.CancellationToken)
.ConfigureAwait(false);
var method = new ConfirmSelect(false);
await ModelSendAsync(in method, k.CancellationToken)
.ConfigureAwait(false);

bool result = await k;
Debug.Assert(result);
bool result = await k;
Debug.Assert(result);

return;
}
finally
{
if (false == enqueued)
{
k.Dispose();
}
}
return;
}
}

Expand Down
Loading

0 comments on commit 36ac973

Please sign in to comment.