Skip to content

Commit

Permalink
Test change to throw exception when openasync http request fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmartinezramirez committed Jul 29, 2024
1 parent 982a1e4 commit ec0c0fa
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions Snowflake.Data/Core/HttpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace Snowflake.Data.Core
{
using Client;

public class HttpClientConfig
{
public HttpClientConfig(
Expand Down Expand Up @@ -87,7 +89,7 @@ public sealed class HttpUtil

private HttpUtil()
{
// This value is used by AWS SDK and can cause deadlock,
// This value is used by AWS SDK and can cause deadlock,
// so we need to increase the default value of 2
// See: https://github.com/aws/aws-sdk-net/issues/152
ServicePointManager.DefaultConnectionLimit = 50;
Expand Down Expand Up @@ -181,15 +183,15 @@ internal HttpMessageHandler SetupCustomHttpHandler(HttpClientConfig config)
{
// Get the original entry
entry = bypassList[i].Trim();
// . -> [.] because . means any char
// . -> [.] because . means any char
entry = entry.Replace(".", "[.]");
// * -> .* because * is a quantifier and need a char or group to apply to
entry = entry.Replace("*", ".*");

entry = entry.StartsWith("^") ? entry : $"^{entry}";

entry = entry.EndsWith("$") ? entry : $"{entry}$";

// Replace with the valid entry syntax
bypassList[i] = entry;

Expand Down Expand Up @@ -373,7 +375,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

while (true)
{

Exception toThrow = null;
try
{
childCts = null;
Expand All @@ -384,7 +386,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
if (httpTimeout.Ticks == 0)
childCts.Cancel();
else
childCts.CancelAfter(httpTimeout);
childCts.CancelAfter(httpTimeout);
}
response = await base.SendAsync(requestMessage, childCts == null ?
cancellationToken : childCts.Token).ConfigureAwait(false);
Expand All @@ -406,6 +408,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
//TODO: Should probably check to see if the error is recoverable or transient.
logger.Warn("Error occurred during request, retrying...", e);
}
toThrow = e;
}

if (childCts != null)
Expand Down Expand Up @@ -454,7 +457,16 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
return response;
}
throw new OperationCanceledException($"http request failed and max retry {maxRetryCount} reached");


throw new SnowflakeDbException(toThrow, SFError.INTERNAL_ERROR,
$"Http request failed and max retry {maxRetryCount} reached");

}

if (childCts.IsCancellationRequested)
{
throw new OperationCanceledException($"cancelado!!!");
}

// Disposing of the response if not null now that we don't need it anymore
Expand Down

0 comments on commit ec0c0fa

Please sign in to comment.