From fb6ba1258c2f5e2353632bc6686ac32ae0e1598f Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Wed, 1 Jul 2020 14:28:53 +0200 Subject: [PATCH] Consistently apply ConfigureAwait(false) in elastic cache --- .../Internal/Util/_bcl+netstandard/DecryptStream.cs | 2 +- .../Internal/Util/_mobile/AsyncHelpers.cs | 4 ++-- .../Amazon.Runtime/Internal/_async/AsyncRunner.cs | 2 +- .../Pipeline/HttpHandler/HttpHandler.cs | 12 ++++++------ .../HttpHandler/_bcl/HttpWebRequestFactory.cs | 8 ++++---- .../_bcl+netstandard/AWSSDKUtils.bcl+netstandard.cs | 2 +- .../_bcl45+netstandard+pcl/AWSHttpClient.cs | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sdk/src/Core/Amazon.Runtime/Internal/Util/_bcl+netstandard/DecryptStream.cs b/sdk/src/Core/Amazon.Runtime/Internal/Util/_bcl+netstandard/DecryptStream.cs index 9e3bcaf34d72..944db85a3369 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/Util/_bcl+netstandard/DecryptStream.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/Util/_bcl+netstandard/DecryptStream.cs @@ -116,7 +116,7 @@ public override int Read(byte[] buffer, int offset, int count) /// public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - int result = await this.CryptoStream.ReadAsync(buffer, offset, count, cancellationToken); + int result = await this.CryptoStream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); return result; } #endif diff --git a/sdk/src/Core/Amazon.Runtime/Internal/Util/_mobile/AsyncHelpers.cs b/sdk/src/Core/Amazon.Runtime/Internal/Util/_mobile/AsyncHelpers.cs index 4797fed85844..9f84fd991147 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/Util/_mobile/AsyncHelpers.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/Util/_mobile/AsyncHelpers.cs @@ -26,7 +26,7 @@ public static void RunSync(Func workItem) { try { - await workItem(); + await workItem().ConfigureAwait(false); } catch (Exception e) { @@ -58,7 +58,7 @@ public static T RunSync(Func> workItem) { try { - ret = await workItem(); + ret = await workItem().ConfigureAwait(false); } catch (Exception e) { diff --git a/sdk/src/Core/Amazon.Runtime/Internal/_async/AsyncRunner.cs b/sdk/src/Core/Amazon.Runtime/Internal/_async/AsyncRunner.cs index 205bb8f9c84b..c12d6628e885 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/_async/AsyncRunner.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/_async/AsyncRunner.cs @@ -71,7 +71,7 @@ public static Task Run(Func action, CancellationToken cancellationToken #endif { thread.Start(); - await semaphore.WaitAsync(); + await semaphore.WaitAsync().ConfigureAwait(false); thread.Join(); if (exception != null) diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/HttpHandler.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/HttpHandler.cs index 740433c80526..0c0ab9765ab3 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/HttpHandler.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/HttpHandler.cs @@ -161,7 +161,7 @@ public override async System.Threading.Tasks.Task InvokeAsync(IExecutionCo // where the stream is a property of the request. #if BCL45 var requestContent = await httpRequest.GetRequestContentAsync(executionContext.RequestContext.CancellationToken).ConfigureAwait(false); - await WriteContentToRequestBodyAsync(requestContent, httpRequest, executionContext.RequestContext); + await WriteContentToRequestBodyAsync(requestContent, httpRequest, executionContext.RequestContext).ConfigureAwait(false); #else var requestContent = await httpRequest.GetRequestContentAsync().ConfigureAwait(false); WriteContentToRequestBody(requestContent, httpRequest, executionContext.RequestContext); @@ -181,8 +181,8 @@ public override async System.Threading.Tasks.Task InvokeAsync(IExecutionCo } var response = await httpRequest.GetResponseAsync(executionContext.RequestContext.CancellationToken). - ConfigureAwait(false); - executionContext.ResponseContext.HttpResponse = response; + ConfigureAwait(false); + executionContext.ResponseContext.HttpResponse = response; } // The response is not unmarshalled yet. return null; @@ -439,7 +439,7 @@ private async System.Threading.Tasks.Task WriteContentToRequestBodyAsync(TReques { byte[] requestData = wrappedRequest.Content; requestContext.Metrics.AddProperty(Metric.RequestSize, requestData.Length); - await httpRequest.WriteToRequestBodyAsync(requestContent, requestData, requestContext.Request.Headers, requestContext.CancellationToken); + await httpRequest.WriteToRequestBodyAsync(requestContent, requestData, requestContext.Request.Headers, requestContext.CancellationToken).ConfigureAwait(false); } else { @@ -447,7 +447,7 @@ private async System.Threading.Tasks.Task WriteContentToRequestBodyAsync(TReques if (wrappedRequest.ContentStream == null) { originalStream = new System.IO.MemoryStream(); - await originalStream.WriteAsync(wrappedRequest.Content, 0, wrappedRequest.Content.Length, requestContext.CancellationToken); + await originalStream.WriteAsync(wrappedRequest.Content, 0, wrappedRequest.Content.Length, requestContext.CancellationToken).ConfigureAwait(false); originalStream.Position = 0; } else @@ -460,7 +460,7 @@ private async System.Threading.Tasks.Task WriteContentToRequestBodyAsync(TReques originalStream = httpRequest.SetupProgressListeners(originalStream, requestContext.ClientConfig.ProgressUpdateInterval, this.CallbackSender, callback); var inputStream = GetInputStream(requestContext, originalStream, wrappedRequest); await httpRequest.WriteToRequestBodyAsync(requestContent, inputStream, - requestContext.Request.Headers, requestContext); + requestContext.Request.Headers, requestContext).ConfigureAwait(false); } } diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_bcl/HttpWebRequestFactory.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_bcl/HttpWebRequestFactory.cs index 86fda7dc3c8b..c2cbcfe550e0 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_bcl/HttpWebRequestFactory.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_bcl/HttpWebRequestFactory.cs @@ -284,10 +284,10 @@ public async Task WriteToRequestBodyAsync(Stream requestContent, Stream contentS int bytesRead = 0; int bytesToRead = buffer.Length; - while ((bytesRead = await contentStream.ReadAsync(buffer, 0, bytesToRead, requestContext.CancellationToken)) > 0) + while ((bytesRead = await contentStream.ReadAsync(buffer, 0, bytesToRead, requestContext.CancellationToken).ConfigureAwait(false)) > 0) { requestContext.CancellationToken.ThrowIfCancellationRequested(); - await requestContent.WriteAsync(buffer, 0, bytesRead, requestContext.CancellationToken); + await requestContent.WriteAsync(buffer, 0, bytesRead, requestContext.CancellationToken).ConfigureAwait(false); } } catch @@ -327,7 +327,7 @@ public async Task WriteToRequestBodyAsync(Stream requestContent, Stream contentS cancellationToken.ThrowIfCancellationRequested(); using (requestContent) { - await requestContent.WriteAsync(content, 0, content.Length, cancellationToken); + await requestContent.WriteAsync(content, 0, content.Length, cancellationToken).ConfigureAwait(false); } } @@ -337,7 +337,7 @@ public async Task WriteToRequestBodyAsync(Stream requestContent, Stream contentS /// public async Task GetRequestContentAsync() { - return await GetRequestContentAsync(CancellationToken.None); + return await GetRequestContentAsync(CancellationToken.None).ConfigureAwait(false); } /// diff --git a/sdk/src/Core/Amazon.Util/_bcl+netstandard/AWSSDKUtils.bcl+netstandard.cs b/sdk/src/Core/Amazon.Util/_bcl+netstandard/AWSSDKUtils.bcl+netstandard.cs index 2c24ff980f06..97a7907e7c93 100644 --- a/sdk/src/Core/Amazon.Util/_bcl+netstandard/AWSSDKUtils.bcl+netstandard.cs +++ b/sdk/src/Core/Amazon.Util/_bcl+netstandard/AWSSDKUtils.bcl+netstandard.cs @@ -128,7 +128,7 @@ public static async Task RunProcessAsync(ProcessStartInf var standardErrorTask = process.StandardError.ReadToEndAsync(); var standardOutputTask = process.StandardOutput.ReadToEndAsync(); - await Task.WhenAll(tcs.Task, standardErrorTask, standardOutputTask); + await Task.WhenAll(tcs.Task, standardErrorTask, standardOutputTask).ConfigureAwait(false); return new ProcessExecutionResult { diff --git a/sdk/src/Core/Amazon.Util/_bcl45+netstandard+pcl/AWSHttpClient.cs b/sdk/src/Core/Amazon.Util/_bcl45+netstandard+pcl/AWSHttpClient.cs index 593803597d16..760396a4b51c 100644 --- a/sdk/src/Core/Amazon.Util/_bcl45+netstandard+pcl/AWSHttpClient.cs +++ b/sdk/src/Core/Amazon.Util/_bcl45+netstandard+pcl/AWSHttpClient.cs @@ -150,7 +150,7 @@ public async Task, HttpStatusCode>>> GetR HttpMethod httpMethod = new HttpMethod(httpMethodValue); var headers = new List, HttpStatusCode>>(); var request = new HttpRequestMessage(httpMethod, url); - var response = await _httpClient.SendAsync(request); + var response = await _httpClient.SendAsync(request).ConfigureAwait(false); foreach (var header in response.Headers) { headers.Add(new Tuple, HttpStatusCode>(header.Key, header.Value, response.StatusCode));