Skip to content

Commit 36ac973

Browse files
danielmarbachlukebakken
authored andcommitted
Maxing sure continuations are consistently disposed because they tend to create timer based cancellation token sources and linked tokens
1 parent 6670384 commit 36ac973

File tree

2 files changed

+59
-187
lines changed

2 files changed

+59
-187
lines changed

projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,38 +131,27 @@ private async Task MaybeConfirmSelect(CancellationToken cancellationToken)
131131
if (_publisherConfirmationsEnabled)
132132
{
133133
// NOTE: _rpcSemaphore is held
134-
bool enqueued = false;
135-
var k = new ConfirmSelectAsyncRpcContinuation(ContinuationTimeout, cancellationToken);
134+
using var k = new ConfirmSelectAsyncRpcContinuation(ContinuationTimeout, cancellationToken);
136135

137-
try
136+
if (_nextPublishSeqNo == 0UL)
138137
{
139-
if (_nextPublishSeqNo == 0UL)
138+
if (_publisherConfirmationTrackingEnabled)
140139
{
141-
if (_publisherConfirmationTrackingEnabled)
142-
{
143-
_confirmsTaskCompletionSources.Clear();
144-
}
145-
_nextPublishSeqNo = 1;
140+
_confirmsTaskCompletionSources.Clear();
146141
}
142+
_nextPublishSeqNo = 1;
143+
}
147144

148-
enqueued = Enqueue(k);
145+
Enqueue(k);
149146

150-
var method = new ConfirmSelect(false);
151-
await ModelSendAsync(in method, k.CancellationToken)
152-
.ConfigureAwait(false);
147+
var method = new ConfirmSelect(false);
148+
await ModelSendAsync(in method, k.CancellationToken)
149+
.ConfigureAwait(false);
153150

154-
bool result = await k;
155-
Debug.Assert(result);
151+
bool result = await k;
152+
Debug.Assert(result);
156153

157-
return;
158-
}
159-
finally
160-
{
161-
if (false == enqueued)
162-
{
163-
k.Dispose();
164-
}
165-
}
154+
return;
166155
}
167156
}
168157

0 commit comments

Comments
 (0)