Skip to content

RestClient closes stream for ResponseEntity<InputStream> responses #36492

@lgemeinhardt

Description

@lgemeinhardt

After migrating from version 7.0.5 to 7.0.6 the RestClient using https://github.com/ooraini/gotenberg-spring/ does not work anymore (stream is closed before body could be read).

Here is the sample code

HttpServiceProxyFactory.builderFor(RestClientAdapter.create(RestClient.builder().baseUrl("https://demo.gotenberg.dev").build()))
	.build()
	.createClient(GotenbergClient.class)
	.screenshotUrl("https://www.google.com", GotenbergClient.chromiumScreenshotOptions())
	.getBody()
	.readAllBytes();

Works with 7.0.5 and crashes with 7.0.6

Exception in thread "main" org.apache.hc.core5.http.StreamClosedException: Stream already closed
	at org.apache.hc.core5.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:162)
	at org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:138)
	at java.base/java.io.FilterInputStream.read(FilterInputStream.java:119)
	at java.base/java.io.PushbackInputStream.read(PushbackInputStream.java:185)
	at java.base/java.io.InputStream.readNBytes(InputStream.java:411)
	at java.base/java.io.InputStream.readAllBytes(InputStream.java:348)

It looks like, that #36380 triggers the new behaviour.
The new isStreamingResult method in DefaultRestClient does not work correctly, because the body (InputStream) is wrapped within a ResponseEntity (so instanceof does not work).
In the result close is not set (correctly) to false and closes the stream to early.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions