Thorbenl opened a new pull request, #281:
URL: https://github.com/apache/pulsar-dotpulsar/pull/281
## Summary
- `Awaiter.CreateTask` and `AddTaskCompletionSource` used
`ConcurrentDictionary.TryAdd` which silently discards the new
`TaskCompletionSource` when the key already exists
- During producer reconnection, messages are resent with the same sequence
IDs — new TCS registrations are silently dropped, so broker receipts complete
the old (cancelled) TCS instead of the new one
- This causes `ProducerSendReceiptOrderingException` in
`SubProducer.ProcessReceipt` because the receipt for the head of the send queue
is never observed
## Root Cause
When a producer reconnects (e.g. due to auth token rotation or broker
restart), `EstablishNewChannel` cancels the old dispatcher and creates a new
channel. The send queue cursor is reset, so pending messages are resent with
their original sequence IDs. In `RequestResponseHandler`,
`Awaiter.AddTaskCompletionSource` is called for each resent message — but
`TryAdd` returns `false` for duplicate keys and the new TCS is discarded. The
broker's receipt then completes the old TCS (already cancelled during channel
teardown), and the new TCS never receives a result.
## Fix
Introduced a private `AddOrReplace` method that:
1. Removes any existing entry for the key (cancelling the old TCS)
2. Adds the new TCS
This ensures resent messages always have a live TCS to receive broker
receipts.
## Tests
Added `AwaiterTests` with 8 unit tests covering:
- Basic `SetResult`, `Cancel`, `Dispose` behavior
- `SetResult` with no matching entry (no-op, no throw)
- **Duplicate key handling** via both `CreateTask` and
`AddTaskCompletionSource`:
- Old TCS is cancelled when replaced
- New TCS receives the result on `SetResult`
All 8 tests pass. Full unit test suite: 232/233 pass (1 pre-existing
`ZstdCompressionTests` failure unrelated to this change — compression library
loading on macOS ARM64).
Fix #280
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]