Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Add missing ConfigureAwait(false) calls #241

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Adds `ConfigureAwait(false)` calls to async calls (https://github.com/microsoft/kiota-http-dotnet/issues/240).

## [1.3.11] - 2024-04-19

## Changed
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/HttpRequestMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ internal static async Task<HttpRequestMessage> CloneAsync(this HttpRequestMessag
// HttpClient doesn't rewind streams and we have to explicitly do so.
var contentStream = new MemoryStream();
#if NET5_0_OR_GREATER
await originalRequest.Content.CopyToAsync(contentStream, cancellationToken);
await originalRequest.Content.CopyToAsync(contentStream, cancellationToken).ConfigureAwait(false);
#else
await originalRequest.Content.CopyToAsync(contentStream);
await originalRequest.Content.CopyToAsync(contentStream).ConfigureAwait(false);
#endif

if(contentStream.CanSeek)
Expand Down
76 changes: 38 additions & 38 deletions src/HttpClientRequestAdapter.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Middleware/ChaosHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
return chaosResponse;
}

return await base.SendAsync(request, cancellationToken);
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/CompressionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
request.Headers.AcceptEncoding.Add(gzipQHeaderValue);
}

HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
HttpResponseMessage response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

// Decompress response content when Content-Encoding: gzip header is present.
if(ShouldDecompressContent(response))
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/HeadersInspectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
options.RequestHeaders[contentHeaders.Key] = contentHeaders.Value.ToArray();
}
}
var response = await base.SendAsync(request, cancellationToken);
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
if(options.InspectResponseHeaders)
{
foreach(var header in response.Headers)
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/RedirectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{

// send request first time to get response
var response = await base.SendAsync(request, cancellationToken);
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

// check response status code and redirect handler option
if(ShouldRedirect(response, redirectOption))
Expand Down Expand Up @@ -99,7 +99,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
return response;// We can't clone the original request to replay it.
}
var newRequest = await originalRequest.CloneAsync(cancellationToken);
var newRequest = await originalRequest.CloneAsync(cancellationToken).ConfigureAwait(false);

// status code == 303: change request method from post to get and content to be null
if(response.StatusCode == HttpStatusCode.SeeOther)
Expand Down Expand Up @@ -135,7 +135,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}

// Send redirect request to get response
response = await base.SendAsync(newRequest, cancellationToken);
response = await base.SendAsync(newRequest, cancellationToken).ConfigureAwait(false);

// Check response status code
if(ShouldRedirect(response, redirectOption))
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/RetryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage respo

while(retryCount < retryOption.MaxRetry)
{
exceptions.Add(await GetInnerExceptionAsync(response));
exceptions.Add(await GetInnerExceptionAsync(response).ConfigureAwait(false));
using var retryActivity = activitySource?.StartActivity($"{nameof(RetryHandler)}_{nameof(SendAsync)} - attempt {retryCount}");
retryActivity?.SetTag("http.retry_count", retryCount);
retryActivity?.SetTag("http.status_code", response.StatusCode);
Expand Down Expand Up @@ -139,7 +139,7 @@ private async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage respo
AddOrUpdateRetryAttempt(request, retryCount);

// Delay time
await delay;
await delay.ConfigureAwait(false);

// Call base.SendAsync to send the request
response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
Expand All @@ -150,7 +150,7 @@ private async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage respo
}
}

exceptions.Add(await GetInnerExceptionAsync(response));
exceptions.Add(await GetInnerExceptionAsync(response).ConfigureAwait(false));

throw new AggregateException($"Too many retries performed. More than {retryCount} retries encountered while sending the request.", exceptions);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/TelemetryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
if(telemetryHandlerOption.TelemetryConfigurator != null)
{
var enrichedRequest = telemetryHandlerOption.TelemetryConfigurator(request);
return await base.SendAsync(enrichedRequest, cancellationToken);
return await base.SendAsync(enrichedRequest, cancellationToken).ConfigureAwait(false);
}

// Just forward the request if TelemetryConfigurator was intentionally set to null
return await base.SendAsync(request, cancellationToken);
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion src/Middleware/UriReplacementHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
try
{
request.RequestUri = uriReplacement.Replace(request.RequestUri);
return await base.SendAsync(request, cancellationToken);
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
finally
{
Expand Down
Loading