Resource Leak When Using S3Client.getObject() with ResponseTransformer.toInputStream()
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
### Describe the bug
A resource leak is observed when retrieving an Amazon S3 object as a stream using `S3Client.getObject()` with `ResponseTransformer.toInputStream()`. This leak occurs despite using both `try-with-resources` for automatic resource management and manual calls to `close()` on the `InputStream`.
**Thread dump observation:**
The thread `response-input-stream-timeout-scheduler` is visible in the dump.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Expected Behavior
When the `ResponseInputStream` returned by `s3Client.getObject(..., ResponseTransformer.toInputStream())` is closed, all associated resources should be released and closed.
### Current Behavior
The thread `response-input-stream-timeout-scheduler` is visible in the dump preventing the module to perform a clean and graceful shutdown.
### Reproduction Steps
**Code Snippet:**
```
import org.apache.commons.io.IOUtils;
try (InputStream inputStream = s3Client.getObject(getObjectRequest, ResponseTransformer.toInputStream())) {
return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
}
```
### Possible Solution
_No response_
### Additional Information/Context
As a workaround, `s3Client.getObject(getObjectRequest, ResponseTransformer.toBytes()).asByteArray();` was used to eliminate stream management.
### AWS Java SDK version used
2.33.4
### JDK version used
JDK17
### Operating System and version
Linux
Contributor guide
Assessment
This issue has not been assessed yet.