Skip to content

Commit e51f6bc

Browse files
authored
Merge pull request #1709 from danielmarbach/try-add
Safeguarding against duplicate sequence numbers
2 parents 43da301 + 9163bcc commit e51f6bc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ await _confirmSemaphore.WaitAsync(cancellationToken)
295295
if (_publisherConfirmationTrackingEnabled)
296296
{
297297
publisherConfirmationTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
298-
_confirmsTaskCompletionSources[publishSequenceNumber] = publisherConfirmationTcs;
298+
if (!_confirmsTaskCompletionSources.TryAdd(publishSequenceNumber, publisherConfirmationTcs))
299+
{
300+
throw new InvalidOperationException($"Failed to track the publisher confirmation for sequence number '{publishSequenceNumber}' because it already exists.");
301+
}
299302
}
300303

301304
_nextPublishSeqNo++;

0 commit comments

Comments
 (0)