-
Notifications
You must be signed in to change notification settings - Fork 51
Description
What is the bug?
The HttpConnection class contains the following code in the Request method:
responseMessage = client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).GetAwaiter().GetResult();
and a little further into the same method:
responseStream = responseMessage.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
These two lines of code are prone to deadlocks due to calling GetAwaiter().GetResult(). This link explains why.
A surprisingly similar issue has been discussed to great length in an ElasticSearch.Net issue as well.
How can one reproduce the bug?
It's difficult to reproduce. Essentially requires continuously calling the Request method from multiple threads to provoke a deadlock. It can be quite common under load in a production environment, however.
What is the expected behavior?
The code should be free of potential deadlocks. I suggest changing the implementation to use the synchronous "Send" method of the System.Net.HttpClient instead.