From 4fc6c60288c1c38dc89aca8424ae2a4c24ecfe25 Mon Sep 17 00:00:00 2001 From: Serkant Karaca Date: Thu, 27 Sep 2018 15:25:22 -0700 Subject: [PATCH] Don't retry runtime operation if close called on the client. (#313) * Don't retry if close called on the client. * Encapsulate closeCalled * add this. --- src/Microsoft.Azure.EventHubs/Amqp/AmqpEventDataSender.cs | 2 +- src/Microsoft.Azure.EventHubs/Amqp/AmqpPartitionReceiver.cs | 2 +- src/Microsoft.Azure.EventHubs/EventHubClient.cs | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) 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);