Skip to content

Cannot get BasicAsyncResponseConsumerFactory to trigger for large responses #1054

Closed

Description

@marcreichman-pfi

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

  1. marcreichman-pfi commented on Aug 13, 2025

    @marcreichman-pfi
    Author

    Just a followup, should this previous block of code be:

        @Override
        protected void data(final ByteBuffer src, final boolean endOfStream) throws ContentTooLongException {
            final int newSize = buffer.length() + src.capacity();
            if (newSize > limit) {
                throw new ContentTooLongException(
                    "entity content is too long [" + newSize + "] for the configured buffer limit [" + limit + "]"
                );
            }
            buffer.append(src);
        }
  2. l-trotta commented on Aug 14, 2025

    @l-trotta
    Contributor

    @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!

  3. l-trotta commented on Aug 14, 2025

    @l-trotta
    Contributor

    @marcreichman-pfi available in 9.0.6 and 9.1.2

  4. marcreichman-pfi commented on Aug 14, 2025

    @marcreichman-pfi
    Author

    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:

    • The check was fixed, the error message still will show at 8192.
    • I know of a 100mb input limit, and how to work around that. The server response is larger than 100 mb sometimes in my testing for large queries, and we have never had to worry about a setting for that.
  5. marcreichman-pfi commented on Aug 20, 2025

    @marcreichman-pfi
    Author

    Hi @l-trotta did you happen to see the previous comment?

  6. l-trotta commented on Aug 21, 2025

    @l-trotta
    Contributor

    The check was fixed, the error message still will show at 8192.

    what do you mean here?

    I know of a 100mb input limit, and how to work around that. The server response is larger than 100 mb sometimes in my testing for large queries, and we have never had to worry about a setting for that.

    right you're manually changing the server's max limit, so just changing the matching setting in the client should be fine.

  7. marcreichman-pfi commented on Aug 22, 2025

    @marcreichman-pfi
    Author

    @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.

  8. l-trotta commented on Aug 22, 2025

    @l-trotta
    Contributor

    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.

    ah thanks, I'll change it to something more meaningful the next release

    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.

    I'm almost sure there's also an output limit, but right now I can't find the documentation where I supposedly read it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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