From e0d33e93d6ae8084ef2d51e543e32e9faf315bed Mon Sep 17 00:00:00 2001 From: serkar Date: Thu, 1 Dec 2016 17:18:06 -0800 Subject: [PATCH] Don't retry if remaining time isn't enough. --- .../Primitives/RetryExponential.cs | 6 ------ .../Primitives/RetryPolicy.cs | 11 ++++++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Azure.EventHubs/Primitives/RetryExponential.cs b/src/Microsoft.Azure.EventHubs/Primitives/RetryExponential.cs index 49c0e59..5914df3 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/RetryExponential.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/RetryExponential.cs @@ -49,12 +49,6 @@ namespace Microsoft.Azure.EventHubs TimeSpan retryAfter = this.minimumBackoff.Add(TimeSpan.FromMilliseconds(nextRetryIntervalSeconds * 1000 + nextRetryIntervalMilliseconds)); retryAfter = retryAfter.Add(TimeSpan.FromSeconds(baseWaitTimeSecs)); - // Don't retry if remaining time isn't enough. - if (remainingTime.TotalSeconds < Math.Max(retryAfter.TotalSeconds, ClientConstants.TimerToleranceInSeconds)) - { - return null; - } - return retryAfter; } diff --git a/src/Microsoft.Azure.EventHubs/Primitives/RetryPolicy.cs b/src/Microsoft.Azure.EventHubs/Primitives/RetryPolicy.cs index c80f729..d4bba51 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/RetryPolicy.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/RetryPolicy.cs @@ -95,7 +95,16 @@ namespace Microsoft.Azure.EventHubs } } - return this.OnGetNextRetryInterval(clientId, lastException, remainingTime, baseWaitTime); + var retryAfter = this.OnGetNextRetryInterval(clientId, lastException, remainingTime, baseWaitTime); + + // Don't retry if remaining time isn't enough. + if (retryAfter == null || + remainingTime.TotalSeconds < Math.Max(retryAfter.Value.TotalSeconds, ClientConstants.TimerToleranceInSeconds)) + { + return null; + } + + return retryAfter; } } } \ No newline at end of file