Skip to content

Commit

Permalink
chore: Add .ConfigureAwait(false) to all async method invocations.
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jan 5, 2024
1 parent 445f7c2 commit 143b785
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/Agent/NewRelic/Agent/Core/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ public async Task TryInjectBrowserScriptAsync(string contentType, string request
if (rumBytes == null)
{
transaction.LogFinest("Skipping RUM Injection: No script was available.");
await baseStream.WriteAsync(buffer, 0, buffer.Length);
await baseStream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
}
else
await BrowserScriptInjectionHelper.InjectBrowserScriptAsync(buffer, baseStream, rumBytes, transaction);
await BrowserScriptInjectionHelper.InjectBrowserScriptAsync(buffer, baseStream, rumBytes, transaction).ConfigureAwait(false);
}

private string TryGetRUMScriptInternal(string contentType, string requestPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static async Task InjectBrowserScriptAsync(byte[] buffer, Stream baseStre
{
// not found, can't inject anything
transaction?.LogFinest("Skipping RUM Injection: No suitable location found to inject script.");
await baseStream.WriteAsync(buffer, 0, buffer.Length);
await baseStream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
return;
}

Expand All @@ -34,13 +34,13 @@ public static async Task InjectBrowserScriptAsync(byte[] buffer, Stream baseStre
if (index < buffer.Length) // validate index is less than buffer length
{
// Write everything up to the insertion index
await baseStream.WriteAsync(buffer, 0, index);
await baseStream.WriteAsync(buffer, 0, index).ConfigureAwait(false);

// Write the RUM script
await baseStream.WriteAsync(rumBytes, 0, rumBytes.Length);
await baseStream.WriteAsync(rumBytes, 0, rumBytes.Length).ConfigureAwait(false);

// Write the rest of the doc, starting after the insertion index
await baseStream.WriteAsync(buffer, index, buffer.Length - index);
await baseStream.WriteAsync(buffer, index, buffer.Length - index).ConfigureAwait(false) ;
}
else
transaction?.LogFinest($"Skipping RUM Injection: Insertion index was invalid.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
Expand Down Expand Up @@ -65,7 +65,7 @@ protected void TestConnection()
wc.DownloadString(testAddress);
}
#else
_lazyHttpClient.Value.GetAsync(testAddress).GetAwaiter().GetResult();
_lazyHttpClient.Value.GetAsync(testAddress).ConfigureAwait(false).GetAwaiter().GetResult();
#endif
Log.Info("Connection test to \"{0}\" succeeded", testAddress);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#if !NETFRAMEWORK
Expand Down Expand Up @@ -32,7 +32,7 @@ public void Dispose()
public async Task<IHttpResponseMessageWrapper> SendAsync(HttpRequestMessage message)
{
var cts = new CancellationTokenSource(_timeoutMilliseconds);
return new HttpResponseMessageWrapper(await _httpClient.SendAsync(message, cts.Token));
return new HttpResponseMessageWrapper(await _httpClient.SendAsync(message, cts.Token).ConfigureAwait(false));
}

public TimeSpan Timeout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#if !NETFRAMEWORK
Expand Down Expand Up @@ -37,7 +37,7 @@ public async Task<string> GetContentAsync()
return Constants.EmptyResponseBody;
}

var responseStream = await _httpResponseMessageWrapper.Content.ReadAsStreamAsync();
var responseStream = await _httpResponseMessageWrapper.Content.ReadAsStreamAsync().ConfigureAwait(false);

var contentTypeEncoding = _httpResponseMessageWrapper.Content.Headers.ContentEncoding;
if (contentTypeEncoding.Contains("gzip"))
Expand All @@ -48,7 +48,7 @@ public async Task<string> GetContentAsync()
using (responseStream)
using (var reader = new StreamReader(responseStream, Encoding.UTF8))
{
var responseBody = await reader.ReadLineAsync();
var responseBody = await reader.ReadLineAsync().ConfigureAwait(false);

if (responseBody != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#if !NETFRAMEWORK
Expand Down Expand Up @@ -65,7 +65,7 @@ public override async Task<IHttpResponse> SendAsync(IHttpRequest request)
req.Content.Headers.Add(contentHeader.Key, contentHeader.Value);
}

var response = await _httpClientWrapper.SendAsync(req);
var response = await _httpClientWrapper.SendAsync(req).ConfigureAwait(false);

var httpResponse = new HttpResponse(request.RequestGuid, response);
return httpResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private async Task<int> WaitForResponse()
var success = false;
try
{
success = await _responseStream.MoveNext(_streamCancellationToken);
success = await _responseStream.MoveNext(_streamCancellationToken).ConfigureAwait(false);
}
catch (RpcException rpcEx)
{
Expand Down Expand Up @@ -774,7 +774,7 @@ public void Wait(int millisecondsTimeout)
// Wait until there are both no spans to be sent and no workers pending. Performance ?????
while (_collection?.Count > 0 || _workCounter?.Value > 0)
{
await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string SendData(string method, ConnectionInfo connectionInfo, string seri
{

var httpClient = _httpClientFactory.CreateClient(connectionInfo.Proxy, _configuration);

request = new HttpRequest(_configuration)
{
Endpoint = method,
Expand All @@ -62,9 +62,9 @@ public string SendData(string method, ConnectionInfo connectionInfo, string seri
foreach (var header in _requestHeadersMap)
request.Headers.Add(header.Key, header.Value);

using var response = httpClient.SendAsync(request).GetAwaiter().GetResult();
using var response = httpClient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();

var responseContent = response.GetContentAsync().GetAwaiter().GetResult();
var responseContent = response.GetContentAsync().ConfigureAwait(false).GetAwaiter().GetResult();

if (!response.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task Invoke(HttpContext context)
{
_agent.Logger.Log(Agent.Extensions.Logging.Level.Finest, "Skipping instrumenting incoming OPTIONS request.");

await _next(context);
await _next(context).ConfigureAwait(false);
return;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public async Task Invoke(HttpContext context)

try
{
await _next(context);
await _next(context).ConfigureAwait(false);
EndTransaction(segment, transaction, context, null);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override void Write(byte[] buffer, int offset, int count)
// Set a flag on the context to indicate we're in the middle of injecting - prevents multiple recursions when response compression is in use
StartInjecting();
_agent.TryInjectBrowserScriptAsync(_context.Response.ContentType, _context.Request.Path.Value, buffer, _baseStream)
.GetAwaiter().GetResult();
.ConfigureAwait(false).GetAwaiter().GetResult();
}
finally
{
Expand All @@ -102,7 +102,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, Cancella
{
// Set a flag on the context to indicate we're in the middle of injecting - prevents multiple recursions when response compression is in use
StartInjecting();
await _agent.TryInjectBrowserScriptAsync(_context.Response.ContentType, _context.Request.Path.Value, buffer.ToArray(), _baseStream);
await _agent.TryInjectBrowserScriptAsync(_context.Response.ContentType, _context.Request.Path.Value, buffer.ToArray(), _baseStream).ConfigureAwait(false);
}
finally
{
Expand All @@ -113,7 +113,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, Cancella
}

if (_baseStream != null)
await _baseStream.WriteAsync(buffer, cancellationToken);
await _baseStream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false);
}

private const string InjectingRUM = "InjectingRUM";
Expand All @@ -126,7 +126,7 @@ public override async ValueTask DisposeAsync()
{
_context = null;

await _baseStream.DisposeAsync();
await _baseStream.DisposeAsync().ConfigureAwait(false);
_baseStream = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task Invoke(HttpContext context)
{
_agent.Logger.Log(Agent.Extensions.Logging.Level.Finest, "Not instrumenting incoming OPTIONS request.");

await _next(context);
await _next(context).ConfigureAwait(false);
return;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public async Task Invoke(HttpContext context)

try
{
await _next(context);
await _next(context).ConfigureAwait(false);
EndTransaction(segment, transaction, context, null);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task Send(ConsumeContext context, IPipe<ConsumeContext> next)

var segment = transaction.StartMessageBrokerSegment(mc, MessageBrokerDestinationType.Queue, MessageBrokerAction.Consume, MessageBrokerVendorName, queueData.QueueName);

await next.Send(context);
await next.Send(context).ConfigureAwait(false);
segment.End();
transaction.End();

Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task Send(PublishContext context, IPipe<PublishContext> next)
InsertDistributedTraceHeaders(context.Headers, transaction);
var segment = transaction.StartMessageBrokerSegment(mc, queueData.DestinationType, MessageBrokerAction.Produce, MessageBrokerVendorName, queueData.QueueName);

await next.Send(context);
await next.Send(context).ConfigureAwait(false);
segment.End();
}

Expand All @@ -109,7 +109,7 @@ public async Task Send(SendContext context, IPipe<SendContext> next)
InsertDistributedTraceHeaders(context.Headers, transaction);
var segment = transaction.StartMessageBrokerSegment(mc, queueData.DestinationType, MessageBrokerAction.Produce, MessageBrokerVendorName, queueData.QueueName);

await next.Send(context);
await next.Send(context).ConfigureAwait(false);
segment.End();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task Send(ConsumeContext context, IPipe<ConsumeContext> next)

var segment = transaction.StartMessageBrokerSegment(mc, MessageBrokerDestinationType.Queue, MessageBrokerAction.Consume, MessageBrokerVendorName, queueData.QueueName);

await next.Send(context);
await next.Send(context).ConfigureAwait(false);
segment.End();
transaction.End();

Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task Send(PublishContext context, IPipe<PublishContext> next)
InsertDistributedTraceHeaders(context.Headers, transaction);
var segment = transaction.StartMessageBrokerSegment(mc, queueData.DestinationType, MessageBrokerAction.Produce, MessageBrokerVendorName, queueData.QueueName);

await next.Send(context);
await next.Send(context).ConfigureAwait(false);
segment.End();
}

Expand All @@ -110,7 +110,7 @@ public async Task Send(SendContext context, IPipe<SendContext> next)
InsertDistributedTraceHeaders(context.Headers, transaction);
var segment = transaction.StartMessageBrokerSegment(mc, queueData.DestinationType, MessageBrokerAction.Produce, MessageBrokerVendorName, queueData.QueueName);

await next.Send(context);
await next.Send(context).ConfigureAwait(false);
segment.End();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task Invoke(IOwinContext context)

try
{
await _next.Invoke(context);
await _next.Invoke(context).ConfigureAwait(false);
EndTransaction(segment, transaction, context, null);
}
catch (Exception ex)
Expand Down

0 comments on commit 143b785

Please sign in to comment.