aws / aws/aws-encryption-sdk-javascript

decryptStream causes unbounded memory growth

Offen Anfängerfreundlich
#1,656 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
260
Forks
68
Ø Merge
22 Std. 19 Min.
Gemergte PRs (30 T.)
2

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne am Einstiegspunkt `_decryptStream` und untersuche die Pipeline, die `parseHeaderStream`, `verifyStream` und `decipherStream` mit dem `PassThrough` verbindet. Ersetze die Senke für ungelesene Ausgaben wie beschrieben und validiere anschließend, indem du ein großes S3-Objekt streamst und bestätigst, dass der Speicher nicht mehr mit der Objektgröße wächst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
aws, node.js, typescript
Bereich
backend, cloud, stream-processing
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.