Skip to content

Commit

Permalink
fix: destroy pipeline streams when returned stream errors (#2437)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ddelgrosso1 and gcf-owl-bot[bot] committed Apr 15, 2024
1 parent 1b71fcc commit fe1ac65
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,16 @@ class File extends ServiceObject<File, FileMetadata> {
emitStream.write(chunk, encoding, cb);
},
});
// If the write stream, which is returned to the caller, catches an error we need to make sure that
// at least one of the streams in the pipeline below gets notified so that they
// all get cleaned up / destroyed.
writeStream.once('error', e => {
emitStream.destroy(e);
});
// If the write stream is closed, cleanup the pipeline below by calling destroy on one of the streams.
writeStream.once('close', () => {
emitStream.destroy();
});

const transformStreams: Transform[] = [];

Expand Down

0 comments on commit fe1ac65

Please sign in to comment.