Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Deadlock prone code in HttpConnection.cs #689 #737

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DavidPoulsenHGS
Copy link

Description

Fixes deadlock prone code in HttpConnection.cs. Changed synchronous methods in HttpConnection.cs to use Task.Run/Task.Wait to avoid deadlocks in accordance with: https://learn.microsoft.com/en-us/archive/blogs/jpsanders/asp-net-do-not-use-task-result-in-main-context

Issues Resolved

#689

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -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
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)?

@@ -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
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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants