Skip to content

TimeoutExceptions on REST Client - with fix proposal #24069

@Sanne

Description

@Sanne

Elasticsearch version:

5.3

Plugins installed: N/A

JVM version: All

OS version: Any

While running integration tests for the Hibernate Search project we noticed some requests failing for TimeoutException on rather slow machines. I initially thought it was a "just a timeout", but investigating I actually identified a problem caused by the default configuration applied by the Elasticsearch REST client.

The Apache Async HTTP client being used has a pool for Non-blocking HTTP connections, implemented by org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager. This pool has a connection property which can be set via org.apache.http.client.config.RequestConfig.Builder.connectionRequestTimeout, but the name seems to have been confusing (it certainly confused me).

This configuration property validates if the Request is stale; for some reason it's also applied to instances of org.apache.http.nio.pool.LeaseRequest , and the next lease instance is validated from a queue of requests even after the execution of a successul client Request. When this second request is expired, the whole execution is marked with a TimeoutException.

To clarify: the client code sends a request A to the Elasticsearch server. A is processed fine, and the response is handled fine as well. after this, the state of A is marked as "timed out" because the next request in the PoolingNHttpClientConnectionManager is an expired lease instance.
I suspect this is a bug in the Apache Async client code as the error handling is essentially returning an exception which seems out of place.

The solution for us was extremely simple: set this property to zero, to disable this lease mechanism.

This mechanism is disabled by default in the Apache Async Http library, but the Elasticsearch client overrides this with its own default:
org.elasticsearch.client.RestClientBuilder.DEFAULT_CONNECTION_REQUEST_TIMEOUT_MILLIS

I'd recommend to set this default to zero as well. The name of the property is probably misleading? It's not really applied to the request processing on the Elasticsearch server, it's applied to the "request to the connection pool".

Thanks!

Relates to:

I think it's the same problem mentioned here:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions