Skip to content

Clarification regarding correct usage of ResponseInputStream#abort and #close #5978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pepijnve opened this issue Mar 21, 2025 · 0 comments
Labels
documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged.

Comments

@pepijnve
Copy link

Describe the issue

Using a ReponseInputStream in a try-with-resources block combined with a call to abort can lead to a 'premature end of stream' error.

As an example, the following code

s3Client.putObject(b -> b.bucket(bucketName).key("object"), RequestBody.fromString("abcd"));
try (var object = s3Client.getObject(GetObjectRequest.builder().bucket(bucketName).key("object").build())) {
   object.abort();
}

produces an exception with this stack trace

org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 4; received: 0)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:198)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:101)
at org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172)
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:170)
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:170)
at software.amazon.awssdk.core.io.SdkFilterInputStream.close(SdkFilterInputStream.java:83)

Is this the expected behaviour? The javadoc for ReponseInputStream seems to suggest that abort should be used instead of close. That does make it rather difficult to use abort in combination with try-with-resources.

Links

https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/ResponseInputStream.html

@pepijnve pepijnve added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant