I'm confused with the very existence of the property:

spring.http.codecs.max-in-memory-size=

Limit on the number of bytes that can be buffered whenever the input stream needs to be aggregated. This applies only to the auto-configured WebFlux server and WebClient instances. By default this is not set, in which case individual codec defaults apply. Most codecs are limited to 256K by default.

What are the benefits of limiting the number of bytes that can be buffered for whenever a stream needs to be aggregated but not the rest of the time?

Let's consider an API that fetches a list of things:


public Flux<Thing> findThings() {

    return webClient.get()
        .uri("/things")
        .retrieve()
        .bodyToFlux(Thing.class);
}

record Thing(String value) {
}
[
    {
        "value": "abcd"
    },
    {
        "value": "efgh"
    },
    {
        "value": "ijkl"
    },
    {
        "value": "emno"
    }
]

In this mode, whatever is spring.http.codecs.max-in-memory-size= set to, e.g: 1 bytes, it will always work as there is no aggregation happening.

However if the former is adapted to:

public Mono<List<Thing>> findThings() {

    return webClient.get()
        .uri("/things")
        .retrieve()
        .bodyToMono(new ParameterizedTypeReference<>() {});
}

record Thing(String value) {
}

Then we would be facing the exception:

Caused by: org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 1
    at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:99)
    Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 

Why trying to prevent memory pressure on aggregation? but keeping it open bar otherwise? A service could accept a JSON array with a single object of 1MB, but couldn't accept a response JSON object of 1MB.

I feel like I should just set the codec to -1 and simply don't bother with this configuration property. Any recommendations?

0

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.