Repository navigation
Description
I apologize for making an issue for this, but there is no discussion feature.
While testing out the client change for the SafeResponseConsumer in #1046 in the 9.0.5 jar, I realized we were already making a call to setHttpAsyncResponseConsumerFactory to make use of what used to be the HeapBufferedAsyncResponseConsumer, so we could override the default 100 mb limit, in coordination with detecting the ContentTooLongException thrown, to adjust our query on retry. I ported this code in the 9.x client to use the BasicAsyncResponseConsumerFactory which seems to be its substitute, with my final setup looking like this:
this.esJavaClient = new ElasticsearchAsyncClient(transport, new Rest5ClientOptions(
RequestOptions.DEFAULT.toBuilder()
.setHttpAsyncResponseConsumerFactory(() -> new SafeResponseConsumer<>(
new HttpAsyncResponseConsumerFactory
.BasicAsyncResponseConsumerFactory(MAX_RESPONSE_ENTITY_SIZE)
.createHttpAsyncResponseConsumer()))
.build(),
false));I was testing this path with intentional large query responses, because I had to change the ContentTooLongException to the httpclient5 version, and I could never get this to trip. I even set my value as low as 1-2MB and could still not get it to trip.
I noticed in this class, BufferedByteConsumer is used, and in this method, the src.capacity() seems to NEVER be larger than 8192, regardless of how large the response entity is:
@Override
protected void data(final ByteBuffer src, final boolean endOfStream) throws ContentTooLongException {
if (src.capacity() > limit) {
throw new ContentTooLongException(
"entity content is too long [" + src.capacity() + "] for the configured buffer limit [" + limit + "]"
);
}
buffer.append(src);
}Is the entity handling done in some form of streaming buffer fashion such that we don't need to worry about entity response sizes anymore, or receiving a stack containing ContentTooLongException? If this is the case I can adjust our code to not override the async response factory at all, which will also simplify things to use the default setup with the safe consumer as was recently put into 9.0.5.
Activity
marcreichman-pfi commentedon Aug 13, 2025
Just a followup, should this previous block of code be:
l-trotta commentedon Aug 14, 2025
@marcreichman-pfi thank you for investigating this! the buffer is filled by a stream of data, but in the end the elasticsearch server does have a 100MB limit, so we should've checked the whole size like you're pointing out. I'll perform some tests just to be sure and will release a quick patch. Thanks a lot!
l-trotta commentedon Aug 14, 2025
@marcreichman-pfi available in 9.0.6 and 9.1.2
marcreichman-pfi commentedon Aug 14, 2025
Thanks @l-trotta ! I will roll it out when it comes out and then test with artificially low numbers to make sure it trips..
Two quick bits:
marcreichman-pfi commentedon Aug 20, 2025
Hi @l-trotta did you happen to see the previous comment?
l-trotta commentedon Aug 21, 2025
what do you mean here?
right you're manually changing the server's max limit, so just changing the matching setting in the client should be fine.
marcreichman-pfi commentedon Aug 22, 2025
@l-trotta
In your changes the check was fixed, but if it’s exceeded the error printed doesn’t contain that value, it just includes sec.capacity.
The limit I discussed raising is the http input limit. I am not aware of any output size limit, which would correspond with this particular error.
l-trotta commentedon Aug 22, 2025
ah thanks, I'll change it to something more meaningful the next release
I'm almost sure there's also an output limit, but right now I can't find the documentation where I supposedly read it.