Skip to content

Semaphore exception when publishing with confirmation #1818

Open
@patriktiain

Description

@patriktiain

Describe the bug

Found on client version 7.1.1

I'm running in parallel allowing multiple threads using the same IChannel instance to publish message with confirmation.

When we use the version 6 of the client we had a channel pool to make sure that the channel wasn't shared between threads but when we upgraded to version 7 and got noticed that it might be thread safe (From discussion like this one #1721). We have started to test with a more liberal channel pool that allows multiple threads publish on the same IChannel instance.

After a period testing we have found multiple semaphore exceptions among a burst of confirmation fails. All exceptions happened within one second.

System.InvalidOperationException: BUG FOUND - please report this exception (with stacktrace) here: https://github.com/rabbitmq/rabbitmq-dotnet-client/issuesh
 ---> System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count.
   at System.Threading.SemaphoreSlim.Release(Int32 releaseCount)
   at RabbitMQ.Client.Impl.Channel.MaybeEndPublisherConfirmationTracking(PublisherConfirmationInfo publisherConfirmationInfo, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at RabbitMQ.Client.Impl.Channel.MaybeEndPublisherConfirmationTracking(PublisherConfirmationInfo publisherConfirmationInfo, CancellationToken cancellationToken)
   at RabbitMQ.Client.Impl.Channel.BasicPublishAsync[TProperties](String exchange, String routingKey, Boolean mandatory, TProperties basicProperties, ReadOnlyMemory`1 body, CancellationToken cancellationToken)

We are using RabbitMQ server version 3.11.28 and .Net 8.

Reproduction steps

1.Enable confirmation on channel
2.Publish in parallel on channel

Expected behavior

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions