Skip to content
Closed
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
9 changes: 6 additions & 3 deletions src/OpenSearch.Net/Connection/HttpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public virtual TResponse Request<TResponse>(RequestData requestData)

if (requestData.ThreadPoolStats)
threadPoolStats = ThreadPoolStats.GetStats();

responseMessage = client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).GetAwaiter().GetResult();
var task = Task.Run(() => client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you looked at using client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joefeser .ConfigureAwait(false) is not needed inside a Task.Run since there is no synchronization context to capture.

task.Wait();
responseMessage = task.Result;
statusCode = (int)responseMessage.StatusCode;
d.EndState = statusCode;
}
Expand All @@ -120,7 +121,9 @@ public virtual TResponse Request<TResponse>(RequestData requestData)
if (responseMessage.Content != null)
{
receive = DiagnosticSource.Diagnose(DiagnosticSources.HttpConnection.ReceiveBody, requestData, statusCode);
responseStream = responseMessage.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
var task = Task.Run(() => responseMessage.Content.ReadAsStreamAsync());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you considered just changing it to responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false)?

task.Wait();
responseStream = task.Result;
}
}
catch (TaskCanceledException e)
Expand Down