aws / aws/aws-sdk-java-v2

Resource Leak When Using S3Client.getObject() with ResponseTransformer.toInputStream()

Aperta
#6,567 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug p2
Lingua principale
Java
Stelle
2.6k
Fork
1k
Merge medio
2g 9h
PR unite (30g)
51

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo la perdita con S3Client.getObject() e ResponseTransformer.toInputStream() su JDK 17, quindi esamina il ResponseInputStream restituito e il thread response-input-stream-timeout-scheduler. Verifica che la chiusura dello stream rilasci lo scheduler e consenta uno spegnimento pulito dell'SDK; confronta il comportamento con la soluzione alternativa toBytes().

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, java
Ambito
backend, cloud
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.