fix(eventhubs): stop authorization refresh on close - #5119
Merged
Johnathan W (j7nw4r) merged 14 commits intoSep 1, 2026
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 3 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Johnathan W (j7nw4r)
force-pushed
the
fix/eventhubs-producer-memory-leak
branch
from
August 25, 2026 18:13
ddeaeba to
55dc1cb
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Stops Event Hubs authorization refresh tasks during connection closure to prevent retained producer lifecycle memory.
Changes:
- Cancels refresh tasks before connection teardown.
- Adds deterministic refresh-task cleanup coverage.
- Adds a live heap-growth regression test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/common/authorizer.rs |
Adds refresh-task cancellation and test configuration. |
src/common/recoverable/connection.rs |
Stops refresh during close and adds regression coverage. |
tests/eventhubs_producer_memory.rs |
Adds lifecycle heap-trend testing. |
Suppressed comments (2)
sdk/eventhubs/azure_messaging_eventhubs/tests/eventhubs_producer_memory.rs:70
- A missing Event Hub name also reports this regression test as passed without running any lifecycle. Preserve the fallback name if needed, but propagate failure when neither variable is configured.
let eventhub = match env::var("EVENT_HUB_NAME") {
Ok(eventhub) if !eventhub.is_empty() => eventhub,
_ => match env::var("EVENTHUB_NAME") {
Ok(eventhub) if !eventhub.is_empty() => eventhub,
_ => return Ok(()),
sdk/eventhubs/azure_messaging_eventhubs/tests/eventhubs_producer_memory.rs:76
- Credential construction failure silently turns the live regression into a passing no-op. Since live mode was explicitly requested, propagate this error so an unusable test environment is visible.
let credential = match DeveloperToolsCredential::new(None) {
Ok(credential) => credential,
Err(_) => return Ok(()),
};
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Johnathan W (j7nw4r)
marked this pull request as ready for review
August 27, 2026 15:21
Johnathan W (j7nw4r)
requested review from
Josue Gomez (SwayGom) and
Sagar Patel (sagar0207)
as code owners
August 27, 2026 15:21
|
Azure Pipelines: Successfully started running 1 pipeline(s). 3 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Sagar Patel (sagar0207)
left a comment
Member
There was a problem hiding this comment.
The core task-lifecycle fix looks sound. I found two concerns in the new live test and two documentation follow-ups.
Track live allocation bytes across sequential producer lifecycle tests. Use warmups, block medians, and a noise-adjusted regression bound.
Gate a refresh credential and verify close releases the authorizer task.
Exercise the connection-owned authorizer with a gated refresh credential. Expose only test-gated helpers for deterministic refresh timing and setup.
Use a terminal refresher state to synchronize startup with shutdown. Await task cancellation before close returns so the authorizer ownership cycle is released.
Use the accepted two-word spelling in the producer memory regression test so the pull request spell-check job can complete.
Johnathan W (j7nw4r)
force-pushed
the
fix/eventhubs-producer-memory-leak
branch
2 times, most recently
from
August 31, 2026 13:56
035b9b7 to
47df38c
Compare
Josue Gomez (SwayGom)
approved these changes
Aug 31, 2026
Johnathan W (j7nw4r)
enabled auto-merge (squash)
August 31, 2026 21:57
Use the accepted two-word spelling so the pull request spell-check job can complete.
Keep the authorization shutdown tests compatible with the transport parameter added on main.
Sagar Patel (sagar0207)
approved these changes
Sep 1, 2026
Josue Gomez (SwayGom)
approved these changes
Sep 1, 2026
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
Event Hubs
ProducerClientclose cycles retain authorization refresh task references and can cause sustained heap growth.Motivation
The owned authorization refresh task keeps connection and authorizer references alive during connection teardown. This prevents producer lifecycle memory from being released promptly and matches the reported growth of about 4.8 KB per cycle.
Changes
Stops the owned authorization refresh task before
RecoverableConnectionteardown. Close aborts the refresh task and awaits its cancellation, so task-held references are released before close returns.Replaces
OnceLock<SpawnedTask>with a mutex-backed state machine. This removes the unsafeSendandSyncimplementations.Adds a deterministic regression test for the owned authorization refresh task and documents the fix in the 0.15.0 changelog.
Test plan
cargo fmt -p azure_messaging_eventhubs -- --checkpassed.cargo clippy -p azure_messaging_eventhubs --all-features --all-targets -- -D warningspassed.cargo test -p azure_messaging_eventhubs --all-featurespassed. Tests configured for live service access remained skipped.git diff --checkpassed.Closes #4595