Skip to content

Commit 2812f05

Browse files
authored
[Messaging Clients] Retry IO Exceptions (Azure#19138)
The focus of these changes is to update the retry policies to classify `System.IOException` instances as transient and allow retrying.
1 parent a60deaf commit 2812f05

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Core/BasicRetryPolicy.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Globalization;
6+
using System.IO;
67
using System.Net.Sockets;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -155,6 +156,7 @@ private static bool ShouldRetryException(Exception exception)
155156

156157
case TimeoutException _:
157158
case SocketException _:
159+
case IOException _:
158160
case UnauthorizedAccessException _:
159161
return true;
160162

sdk/eventhub/Azure.Messaging.EventHubs.Shared/tests/RetryPolicies/BasicRetryPolicyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Net.Sockets;
78
using System.Threading.Tasks;
89
using Azure.Messaging.EventHubs.Core;
@@ -27,6 +28,7 @@ public static IEnumerable<object[]> RetriableExceptionTestCases()
2728
{
2829
yield return new object[] { new TimeoutException() };
2930
yield return new object[] { new SocketException(500) };
31+
yield return new object[] { new IOException() };
3032
yield return new object[] { new UnauthorizedAccessException() };
3133

3234
// Task/Operation Canceled should use the inner exception as the decision point.

sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/BasicRetryPolicy.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Globalization;
6+
using System.IO;
67
using System.Net.Sockets;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -142,6 +143,7 @@ private static bool ShouldRetryException(Exception exception)
142143

143144
case TimeoutException _:
144145
case SocketException _:
146+
case IOException _:
145147
case UnauthorizedAccessException _:
146148
return true;
147149

@@ -151,11 +153,11 @@ private static bool ShouldRetryException(Exception exception)
151153
}
152154

153155
/// <summary>
154-
/// Calculates the delay for an exponential backoff.
156+
/// Calculates the delay for an exponential back-off.
155157
/// </summary>
156158
///
157159
/// <param name="attemptCount">The number of total attempts that have been made, including the initial attempt before any retries.</param>
158-
/// <param name="baseDelaySeconds">The delay to use as a basis for the exponential backoff, in seconds.</param>
160+
/// <param name="baseDelaySeconds">The delay to use as a basis for the exponential back-off, in seconds.</param>
159161
/// <param name="baseJitterSeconds">The delay to use as the basis for a random jitter value, in seconds.</param>
160162
/// <param name="random">The random number generator to use for the calculation.</param>
161163
///
@@ -169,10 +171,10 @@ private static TimeSpan CalculateExponentialDelay(
169171
TimeSpan.FromSeconds((Math.Pow(2, attemptCount) * baseDelaySeconds) + (random.NextDouble() * baseJitterSeconds));
170172

171173
/// <summary>
172-
/// Calculates the delay for a fixed backoff.
174+
/// Calculates the delay for a fixed back-off.
173175
/// </summary>
174176
///
175-
/// <param name="baseDelaySeconds">The delay to use as a basis for the fixed backoff, in seconds.</param>
177+
/// <param name="baseDelaySeconds">The delay to use as a basis for the fixed back-off, in seconds.</param>
176178
/// <param name="baseJitterSeconds">The delay to use as the basis for a random jitter value, in seconds.</param>
177179
/// <param name="random">The random number generator to use for the calculation.</param>
178180
///

sdk/servicebus/Azure.Messaging.ServiceBus/tests/Core/BasicRetryPolicyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Net.Sockets;
78
using System.Threading.Tasks;
89
using System.Transactions;
@@ -28,6 +29,7 @@ public static IEnumerable<object[]> RetriableExceptionTestCases()
2829
{
2930
yield return new object[] { new TimeoutException() };
3031
yield return new object[] { new SocketException(500) };
32+
yield return new object[] { new IOException() };
3133
yield return new object[] { new UnauthorizedAccessException() };
3234

3335
// Task/Operation Canceled should use the inner exception as the decision point.

0 commit comments

Comments
 (0)