Skip to content

Default MaximumRetries with not proper handling of httpwebrequest.getresponse can lead to thread hang #2311

@avandych

Description

@avandych

NEST/Elasticsearch.Net version: 2.0.5

Elasticsearch version: 2.4.1

Description of the problem including expected versus actual behavior:
In our environment we experienced strange issue with our machines. They just started to burn all CPU resources and hang.
After investigation we found the place where all our threads hang elasticsearch

After further investigation we also found that maybe HandleException method in HttpConnection doesn't properly handles situation when we got some error in request.GetResponse() and response.GetResponseStream() in HandleException method returns null (looks like underlining tcp connection isn't disposed).

In ASP.NET application ServicePointManager.DefaultConnectionLimit is set to 10.
In your client MaxRetries property in RequestPipeline defaults to int.MaxValue when not configured by user.

What we think happens is - Elasticsearch client uses all 10 connections and don't disposes them properly, connection number 11 established by client hangs in queue waiting when ServicePointManager allows it to be used, CPU is burst to full core usage on that thread.

After we set ConnectionSettings MaximumRetries to 3 all works fine, without cpu burst and hanging.

Our problem was that we used default settings for client.
Many developers that start with your client, start from default settings, and I suggest that it will be good to set default MaximumRetries to 3, so they will not get into similar situation and spend some unnecessary amount of time to figure out what is going on. (3 because ServicePointManager.DefaultConnectionLimit in console app defaults to 3).

The above is only an assumption but I think that it's worth to check it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions