Skip to content

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

@DavidPoulsenHGS

Description

@DavidPoulsenHGS

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions