Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs] Resilient management link creation #46544

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/eventhub/Azure.Messaging.EventHubs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Querying runtime data and other management operations will now correctly guards against the race condition where an AMQP link is in the process of closing as the operation attempts to use it. These errors will now properly be classified as retriable as they are for producer and consumer operations.

### Other Changes

## 5.11.5 (2024-07-31)
Expand Down
31 changes: 30 additions & 1 deletion sdk/eventhub/Azure.Messaging.EventHubs/src/Amqp/AmqpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected AmqpClient(string host,
clientOptions.CertificateValidationCallback);

ManagementLink = new FaultTolerantAmqpObject<RequestResponseAmqpLink>(
linkTimeout => ConnectionScope.OpenManagementLinkAsync(operationTimeout, linkTimeout, CancellationToken.None),
linkTimeout => CreateManagementLinkAsync(operationTimeout, linkTimeout, CancellationToken.None),
link =>
{
link.Session?.SafeClose();
Expand Down Expand Up @@ -545,6 +545,35 @@ public override async Task CloseAsync(CancellationToken cancellationToken)
}
}

/// <summary>
/// Creates the AMQP link to be used for management operations and ensures
/// that any corresponding state has been updated based on the link configuration.
/// </summary>
///
/// <param name="operationTimeout">The timeout to apply to management operations using the link..</param>
/// <param name="linkTimeout">The timeout to apply for creating the link.</param>
/// <param name="cancellationToken">The cancellation token to consider when creating the link.</param>
///
/// <returns>The AMQP link to use for management operations.</returns>
///
private async Task<RequestResponseAmqpLink> CreateManagementLinkAsync(TimeSpan operationTimeout,
TimeSpan linkTimeout,
CancellationToken cancellationToken)
{
var link = default(RequestResponseAmqpLink);

try
{
link = await ConnectionScope.OpenManagementLinkAsync(operationTimeout, linkTimeout, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
jsquire marked this conversation as resolved.
Show resolved Hide resolved
{
ExceptionDispatchInfo.Capture(ex.TranslateConnectionCloseDuringLinkCreationException(EventHubName)).Throw();
}

return link;
}

/// <summary>
/// Acquires an access token for authorization with the Event Hubs service.
/// </summary>
Expand Down
Loading