-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Changes made in Spring 6.1 by removing buffering from the ClientHttpRequest implementations in this commit actually made all streaming implementations now buffering instead of streaming. This due to the use of the FastByteArrayOutputStream in the AbstractStreamingClientHttpRequest instead of the actual underlying OutputStream of the request.
The FastByteArrayOutputStream buffers the output which will lead to OOM errors when sending large payloads (as in the linked StackOverflow question).
See: https://stackoverflow.com/questions/79801951/spring-web-oom-when-streaming-after-update-from-6-0-23-to-version-6-1-4-and-abov
Related: #30557
Reproducer: https://github.com/Manveroo/spring-web-streaming
To use streaming the following RequestCallback implementation works.
RequestCallback requestCallback =
request -> {
if (request instanceof StreamingHttpOutputMessage shom) {
System.out.println("Using Body");
shom.setBody(out ->
{
try (var fis = new BufferedInputStream(new FileInputStream(sourcePath.toFile()))) {
doStream(fis, out);
}
});
} else {
System.out.println("Using OutputStream");
try (var fis = new BufferedInputStream(new FileInputStream(sourcePath.toFile()))) {
doStream(fis, request.getBody());
}
}
};However prior to 6.1.x just doing request.getBody() (the else branch) would work in a streaming way (if bufferng was set to false on the SimpleClientHttpRequestFactory.