diff --git a/src/Microsoft.Azure.EventHubs/Amqp/AmqpEventDataSender.cs b/src/Microsoft.Azure.EventHubs/Amqp/AmqpEventDataSender.cs index 52f7c03..cfa9720 100644 --- a/src/Microsoft.Azure.EventHubs/Amqp/AmqpEventDataSender.cs +++ b/src/Microsoft.Azure.EventHubs/Amqp/AmqpEventDataSender.cs @@ -87,7 +87,7 @@ namespace Microsoft.Azure.EventHubs.Amqp { // Evaluate retry condition? TimeSpan? retryInterval = this.RetryPolicy.GetNextRetryInterval(ex, timeoutHelper.RemainingTime(), ++retryCount); - if (retryInterval != null) + if (retryInterval != null && !this.EventHubClient.CloseCalled) { await Task.Delay(retryInterval.Value).ConfigureAwait(false); shouldRetry = true; diff --git a/src/Microsoft.Azure.EventHubs/Amqp/AmqpPartitionReceiver.cs b/src/Microsoft.Azure.EventHubs/Amqp/AmqpPartitionReceiver.cs index fbe8edd..7ed5380 100644 --- a/src/Microsoft.Azure.EventHubs/Amqp/AmqpPartitionReceiver.cs +++ b/src/Microsoft.Azure.EventHubs/Amqp/AmqpPartitionReceiver.cs @@ -105,7 +105,7 @@ namespace Microsoft.Azure.EventHubs.Amqp { // Evaluate retry condition? TimeSpan? retryInterval = this.RetryPolicy.GetNextRetryInterval(ex, timeoutHelper.RemainingTime(), ++retryCount); - if (retryInterval != null) + if (retryInterval != null && !this.EventHubClient.CloseCalled) { await Task.Delay(retryInterval.Value).ConfigureAwait(false); shouldRetry = true; diff --git a/src/Microsoft.Azure.EventHubs/EventHubClient.cs b/src/Microsoft.Azure.EventHubs/EventHubClient.cs index 0ed7860..782697b 100644 --- a/src/Microsoft.Azure.EventHubs/EventHubClient.cs +++ b/src/Microsoft.Azure.EventHubs/EventHubClient.cs @@ -18,6 +18,7 @@ namespace Microsoft.Azure.EventHubs public abstract class EventHubClient : ClientEntity { EventDataSender innerSender; + bool closeCalled = false; internal EventHubClient(EventHubsConnectionStringBuilder csb) : base($"{nameof(EventHubClient)}{ClientEntity.GetNextId()}({csb.EntityPath})") @@ -241,6 +242,8 @@ namespace Microsoft.Azure.EventHubs /// public sealed override async Task CloseAsync() { + this.closeCalled = true; + EventHubsEventSource.Log.ClientCloseStart(this.ClientId); try { @@ -560,6 +563,8 @@ namespace Microsoft.Azure.EventHubs set; } + internal bool CloseCalled { get => this.closeCalled; } + internal EventDataSender CreateEventSender(string partitionId = null) { return this.OnCreateEventSender(partitionId);