aws / aws/aws-encryption-sdk-javascript
decryptStream causes unbounded memory growth
- Lingua principale
- TypeScript
- Stelle
- 260
- Fork
- 68
- Merge medio
- 22h 19m
- PR unite (30g)
- 2
Descrizione
### Problem:
While using `decryptStream` to stream-decrypt large S3 objects, I noticed a memory increase roughly equal to the size of the object.
I think the issue is that `_decryptStream` returns a duplexify wrapper and internally runs a pipeline:
```
const stream = new Duplexify(parseHeaderStream, decipherStream)
pipeline(
parseHeaderStream,
verifyStream,
decipherStream,
new PassThrough(),
(err: Error) => {
if (err) stream.emit('error', err)
}
)
```
The caller reads from `decipherStream` via the duplexify wrapper. The pipeline also pushes `decipherStream`'s output into the `PassThrough`. Since nothing ever reads from that `PassThrough`, its internal buffer appears to grow without bound.
### Solution:
Replacing the `PassThrough` with a no-op `Writable` that discards chunks fixes the memory growth while still absorbing the `destroy()` call:
```
const drain = new Writable({
write(_chunk, _encoding, callback) {
callback()
},
})
pipeline(
parseHeaderStream,
verifyStream,
decipherStream,
drain,
(err: Error) => {
if (err) stream.emit('error', err)
}
)
```
I tested this change locally and the memory usage stopped increasing while streaming.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia dal punto di ingresso `_decryptStream` e ispeziona la pipeline che collega `parseHeaderStream`, `verifyStream` e `decipherStream` a `PassThrough`. Sostituisci il sink di output non letto come descritto, quindi valida trasmettendo in streaming un oggetto S3 di grandi dimensioni e confermando che la memoria non cresce più con le dimensioni dell’oggetto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- aws, node.js, typescript
- Ambito
- backend, cloud, stream-processing
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 68/100