We're updating the issue view to help you get more done. 

IllegalStateException when sending an Elasticsearch request with a content-length

Description

When content-length is defined, the encoder is a LengthDelimitedEncoder, and even a 0-length write will trigger an exception when the content length has been reached.
The current code allows 0-length writes, and we should protect ourselves against that.

Note: this problem only affects 5.8.0.CR1, but was only witnessed while working on HSEARCH-2849. It is possible that the bug never actually happens in 5.8.0.CR1 because makes it content-length definition rarer.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 at org.hibernate.search.elasticsearch.work.impl.BulkWork.lambda$execute$1(BulkWork.java:75) at org.hibernate.search.util.impl.Futures.lambda$handler$1(Futures.java:57) at java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:870) at java.util.concurrent.CompletableFuture$UniExceptionally.tryFire(CompletableFuture.java:852) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977) at org.hibernate.search.elasticsearch.client.impl.DefaultElasticsearchClient$1.onFailure(DefaultElasticsearchClient.java:108) at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onDefinitiveFailure(RestClient.java:605) at org.elasticsearch.client.RestClient$1.retryIfPossible(RestClient.java:396) at org.elasticsearch.client.RestClient$1.failed(RestClient.java:375) at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134) at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419) at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.exception(HttpAsyncRequestExecutor.java:155) at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:310) at org.apache.http.impl.nio.client.InternalIODispatch.onOutputReady(InternalIODispatch.java:86) at org.apache.http.impl.nio.client.InternalIODispatch.onOutputReady(InternalIODispatch.java:39) at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(AbstractIODispatch.java:152) at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:188) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:341) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Encoding process already completed at org.apache.http.util.Asserts.check(Asserts.java:34) at org.apache.http.impl.nio.codecs.AbstractContentEncoder.assertNotCompleted(AbstractContentEncoder.java:89) at org.apache.http.impl.nio.codecs.LengthDelimitedEncoder.write(LengthDelimitedEncoder.java:102) at org.hibernate.search.elasticsearch.util.impl.GsonHttpEntity$ProgressiveCharBufferWriter.fullyWrite(GsonHttpEntity.java:435) at org.hibernate.search.elasticsearch.util.impl.GsonHttpEntity$ProgressiveCharBufferWriter.flushCurrentBuffer(GsonHttpEntity.java:420) at org.hibernate.search.elasticsearch.util.impl.GsonHttpEntity$ProgressiveCharBufferWriter.attemptFlushPendingBuffers(GsonHttpEntity.java:361) at org.hibernate.search.elasticsearch.util.impl.GsonHttpEntity$ProgressiveCharBufferWriter.flushToOutput(GsonHttpEntity.java:453) at org.hibernate.search.elasticsearch.util.impl.GsonHttpEntity.produceContent(GsonHttpEntity.java:274) at org.apache.http.nio.protocol.BasicAsyncRequestProducer.produceContent(BasicAsyncRequestProducer.java:125) at org.apache.http.impl.nio.client.MainClientExec.produceContent(MainClientExec.java:262) at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.produceContent(DefaultClientExchangeHandlerImpl.java:136) at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.outputReady(HttpAsyncRequestExecutor.java:241) at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:290) ... 10 more

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Affects versions

5.8.0.CR1

Priority

Major