fix(eventhubs): make a read after a partition close throw - #7337
Draft
Johnathan W (j7nw4r) wants to merge 2 commits into
Draft
fix(eventhubs): make a read after a partition close throw#7337Johnathan W (j7nw4r) wants to merge 2 commits into
Johnathan W (j7nw4r) wants to merge 2 commits into
Conversation
A read after PartitionClient::Close must throw a non-transient EventHubsException, and the client must not attach a new receiver. Close sets no state today, so the next ReceiveEvents goes on to the link (#7334). Add ReceiveAfterCloseThrowsWithoutARebuild_LIVEONLY_ to the connection string suite and to the parameterized consumer suite. Each test closes the partition client twice, which pins the idempotent close, then reads and requires the throw. Each test then moves the closed client and reads again, so the closed state must survive a move. Add four static_asserts on PartitionClient. They keep the move available and the copy deleted, so a member that is not movable by default fails the compile instead of the link.
PartitionClient::Close closed the AMQP receiver and set no state on the client. A later ReceiveEvents therefore went on to the closed link. On uAMQP that read gave back an empty pair with no AMQP error, so the call fell through to WaitForIncomingMessage and blocked until the read deadline, then threw a raw OperationCancelledException. Close now marks the client closed before it closes the receiver. ReceiveEvents tests that flag first and throws a non-transient EventHubsException with no AMQP condition. The recover loop tests the same flag before each rebuild attempt, so a Close that runs during a call stops the loop instead of attaching a new receiver on the still open session. A call that already holds events returns them, and it keeps no pending error, because the next call sees the flag and throws. The flag is a std::atomic<bool>, which has no implicit move, so the move constructor and the move assignment are now hand written. Fixes #7334
|
Azure Pipelines: 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes PartitionClient reads after closure by tracking closed state and returning a non-transient exception.
Changes:
- Adds atomic closed-state tracking and custom move operations.
- Prevents receiver recovery after closure.
- Adds live tests and release notes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
partition_client.cpp |
Implements closed-state handling and move operations. |
partition_client.hpp |
Declares closed state and documents behavior. |
consumer_client_test.cpp |
Tests closure and move semantics. |
reattach_connection_string_test.cpp |
Adds connection-string coverage. |
CHANGELOG.md |
Documents the fix. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PartitionClient::Closerecords no state. A laterReceiveEventson the same object does not report that the client is closed. The defect exists only onfeat/link-reattach(#7328) and has not reachedmain, so this pull request stacks on that branch.Motivation
Observed behavior before the fix, on the uAMQP transport: a read after
Closeblocked for the full read deadline (60 seconds measured) and then threw a rawAzure::Core::OperationCancelledException. That is the wrong error type and a long stall.Closeclears the message queue, frees the link, and clearsm_receiverOpen, so no AMQP error reaches the queue and the recover path never runs.TryWaitForIncomingMessagereturns empty with no error, andReceiveEventsfalls through toWaitForIncomingMessage, which blocks until the deadline. The rebuild path that issue #7334 describes remains plausible on the Rust transport and was not proven.Changes
std::atomic<bool> m_closed{false}toPartitionClient; the header now includes<atomic>.Closesets the flag before it closes the receiver.ReceiveEventstests the flag as its first action and throws.recoverlambda tests the flag after the backoff and beforeRebuildReceiver. When the call already holds events, it returns them; when it holds none, it throws.CreateClientClosedExceptionhelper that setsIsTransientto false and leavesErrorConditionempty.std::atomichas a deleted copy constructor and no move constructor, so the defaulted move operations would become deleted. The build is C++14 with no guaranteed copy elision, andConsumerClient::CreatePartitionClientreturnsPartitionClientby value. Copy stays deleted.1.0.0-beta.14 (Unreleased),Bugs Fixed.Known limitation: the closed test inside the
recoverloop has no automated test. It fires only when a link fault and aCloseoverlap inside the rebuild backoff, and this target has no mock AMQP server.Test plan
ReattachConnectionStringTest.ReceiveAfterCloseThrowsWithoutARebuild_LIVEONLY_closes, closes again, reads, and asserts the throw withIsTransientfalse and an emptyErrorCondition. It then repeats the read on a moved-from-closed client. A mirrorTEST_PonConsumerClientTestcovers the AAD live pass.static_asserts pin move-constructible, move-assignable, and copy-deleted. They compile in every build, so ordinary CI checks them.azure-messaging-eventhubs-test.ReattachConnectionStringTest.*reports 2 passed, 3 skipped, 0 failed. The new test passes in 6244 ms, which is connect plus send, not a blocked read.CheckpointStoreTest.TestCheckpointswith a missingEVENTHUB_CONSUMER_GROUP, pre-existing and unrelated.C++ exception with description "Receive Operation was cancelled." thrown in the test body.Closes #7334