Skip to content

RestClient closes stream for ResponseEntity<InputStream> responsesΒ #36492

Closed

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.

Activity

  1. self-assigned this
    on Mar 19, 2026
  2. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    and removed on Mar 24, 2026
  3. added this to the 7.0.7 milestone on Mar 24, 2026
  4. changed the title [-]RestClient does not work correctly (closes the result stream) after migrating from 7.0.5 to 7.0.6[/-] [+]RestClient closes stream for ResponseEntity<InputStream> responses[/+] on Mar 24, 2026
  5. added a commit that references this issue on Mar 24, 2026
    d1950f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions