Skip to content

Commit fe1ac65

Browse files
fix: destroy pipeline streams when returned stream errors (#2437)
* fix: destroy pipeline streams when returned stream errors * handle close on writeStream * use once * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 1b71fcc commit fe1ac65

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎src/file.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,16 @@ class File extends ServiceObject<File, FileMetadata> {
20352035
emitStream.write(chunk, encoding, cb);
20362036
},
20372037
});
2038+
// If the write stream, which is returned to the caller, catches an error we need to make sure that
2039+
// at least one of the streams in the pipeline below gets notified so that they
2040+
// all get cleaned up / destroyed.
2041+
writeStream.once('error', e => {
2042+
emitStream.destroy(e);
2043+
});
2044+
// If the write stream is closed, cleanup the pipeline below by calling destroy on one of the streams.
2045+
writeStream.once('close', () => {
2046+
emitStream.destroy();
2047+
});
20382048

20392049
const transformStreams: Transform[] = [];
20402050

0 commit comments

Comments
 (0)