aws / aws/aws-encryption-sdk-javascript
decryptStream causes unbounded memory growth
- Lenguaje dominante
- TypeScript
- Estrellas
- 260
- Forks
- 68
- Merge medio
- 22 h 19 min
- PR fusionados (30 d)
- 2
Descripción
### 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.
Guía de contribución
Línea de trabajo
Comienza en el punto de entrada `_decryptStream` e inspecciona la canalización que conecta `parseHeaderStream`, `verifyStream` y `decipherStream` con `PassThrough`. Reemplaza el destino de salida no consumido como se describe y valida después transmitiendo un objeto grande de S3 y confirmando que la memoria ya no crece con el tamaño del objeto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- aws, node.js, typescript
- Área
- backend, cloud, stream-processing
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 68/100