LengthDelimitedDecoder 导致 org.apache.http.ConnectionClosedException:内容长度分隔的消息正文过早结束

问题描述

我正在尝试使用 RestHighLevelClient 从 Elasticsearch 中进行搜索,如下所示:

RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder()
builder.setHttpAsyncResponseConsumerFactory(new HttpAsyncResponseConsumerFactory
        .HeapBufferedResponseConsumerFactory(BUFFER_LIMIT))
SearchResponse searchResponse = client.search(searchRequest,builder.build())
return searchResponse

但是对于某些搜索,我不断遇到内容长度错误消息的过早结束,我不知道为什么:

org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 405065025; received: 340164608
    at org.apache.http.impl.nio.codecs.LengthDelimitedDecoder.read(LengthDelimitedDecoder.java:89)
    at org.apache.http.nio.util.SimpleInputBuffer.consumeContent(SimpleInputBuffer.java:66)
    at org.elasticsearch.client.HeapBufferedAsyncResponseConsumer.onContentReceived(HeapBufferedAsyncResponseConsumer.java:96)
    at org.apache.http.nio.protocol.AbstractAsyncResponseConsumer.consumeContent(AbstractAsyncResponseConsumer.java:141)
    at org.apache.http.impl.nio.client.MainClientExec.consumeContent(MainClientExec.java:329)
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.consumeContent(DefaultClientExchangeHandlerImpl.java:153)
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:324)
    at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
    at org.apache.http.impl.nio.client.InternalIOdispatch.onInputReady(InternalIOdispatch.java:81)
    at org.apache.http.impl.nio.client.InternalIOdispatch.onInputReady(InternalIOdispatch.java:39)
    at org.apache.http.impl.nio.reactor.AbstractIOdispatch.inputReady(AbstractIOdispatch.java:121)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
    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:748)

我已经查看了其他“内容长度分隔消息正文的过早结束”问题,它似乎没有解决这个问题,因为这个问题直接嵌入在 Elasticsearch 中。

为什么会这样?什么会导致它过早结束?修复方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)