Skip to content

Commit 165bb89

Browse files
committed
Corrected datetime logic
1 parent c77d024 commit 165bb89

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

csharp/src/Drivers/Databricks/RetryHttpHandler.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using System.Threading;
2323
using System.Threading.Tasks;
2424
using System.IO;
25-
using Apache.Arrow.Adbc.Tracing;
25+
2626

2727
namespace Apache.Arrow.Adbc.Drivers.Databricks
2828
{
@@ -63,6 +63,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
6363

6464
HttpResponseMessage response;
6565
string? lastErrorMessage = null;
66+
DateTime startTime = DateTime.UtcNow;
6667
int attemptCount = 0;
6768
int currentBackoffSeconds = _initialBackoffSeconds;
6869
int totalRetrySeconds = 0;
@@ -91,8 +92,9 @@ protected override async Task<HttpResponseMessage> SendAsync(
9192

9293
attemptCount++;
9394

94-
// Check if we've exceeded the total wait time
95-
if (_retryTimeoutSeconds > 0 && totalRetrySeconds > _retryTimeoutSeconds)
95+
// Check if we've exceeded the timeout
96+
TimeSpan elapsedTime = DateTime.UtcNow - startTime;
97+
if (_retryTimeoutSeconds > 0 && elapsedTime.TotalSeconds > _retryTimeoutSeconds)
9698
{
9799
// We've exceeded the timeout, so break out of the loop
98100
break;
@@ -109,20 +111,20 @@ protected override async Task<HttpResponseMessage> SendAsync(
109111
{
110112
// Use the Retry-After value
111113
waitSeconds = retryAfterSeconds;
112-
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Attempt {attemptCount}.";
114+
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Using server-specified retry after {waitSeconds} seconds. Attempt {attemptCount}.";
113115
}
114116
else
115117
{
116118
// Invalid Retry-After value, use exponential backoff
117119
waitSeconds = CalculateBackoffWithJitter(currentBackoffSeconds);
118-
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Attempt {attemptCount}.";
120+
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Invalid Retry-After header, using exponential backoff of {waitSeconds} seconds. Attempt {attemptCount}.";
119121
}
120122
}
121123
else
122124
{
123125
// No Retry-After header, use exponential backoff
124126
waitSeconds = CalculateBackoffWithJitter(currentBackoffSeconds);
125-
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Attempt {attemptCount}.";
127+
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Using exponential backoff of {waitSeconds} seconds. Attempt {attemptCount}.";
126128
}
127129

128130
// Dispose the response before retrying

0 commit comments

Comments
 (0)