Skip to content

Confirm semaphore#1902

Closed
danielmarbach wants to merge 6 commits intorabbitmq:mainfrom
danielmarbach:confirm-semaphore
Closed

Confirm semaphore#1902
danielmarbach wants to merge 6 commits intorabbitmq:mainfrom
danielmarbach:confirm-semaphore

Conversation

@danielmarbach
Copy link
Collaborator

Proposed Changes

Please describe the big picture of your changes here to communicate to the
RabbitMQ team why we should accept this pull request. If it fixes a bug or
resolves a feature request, be sure to link to that issue.

A pull request that doesn't explain why the change was made has a much
lower chance of being accepted.

If English isn't your first language, don't worry about it and try to
communicate the problem you are trying to solve to the best of your abilities.
As long as we can understand the intent, it's all good.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

Further Comments

If this is a relatively large or complex change, kick off the discussion by
explaining why you chose the solution you did and what alternatives you
considered, etc.

EvheniyHlushko and others added 6 commits February 7, 2026 11:45
…ed during BasicPublishAsync

When CancellationToken is already cancelled during BasicPublishAsync,
_confirmSemaphore.WaitAsync() fails but the finally block unconditionally
releases the semaphore. This breaks the semaphore and allows concurrent
access, corrupting _nextPublishSeqNo.

The fix makes the semaphore release conditional on successful acquisition.
If WaitAsync throws OperationCanceledException, the lease is cleaned up
and no PublisherConfirmationInfo is returned, so the semaphore is not released.
Move the semaphore ownership and release responsibility from MaybeEndPublisherConfirmationTrackingAsync
to the PublisherConfirmationInfo class itself. This improves encapsulation by making the PublisherConfirmationInfo
responsible for managing the semaphore resource it owns.

Changes:
- Add _semaphore field and _semaphoreReleased flag to PublisherConfirmationInfo
- Add ReleaseSemaphore() method with idempotence check
- Update constructor to accept SemaphoreSlim parameter
- Update Dispose() to call ReleaseSemaphore()
- Simplify control flow in MaybeStartPublisherConfirmationTrackingAsync (early return pattern)
- Update MaybeEndPublisherConfirmationTrackingAsync to use ReleaseSemaphore() from info object
Replace `PublisherConfirmLeaseFactory` with streamlined semaphore and rate limiter for managing publisher confirmations. Simplify resource disposal, improve clarity, and ensure proper handling of async operations with dedicated methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants