Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/packages/gax/src/streamArrayParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ export class StreamArrayParser extends Transform {
callback();
}

_destroy(err: Error | null, callback: (error?: Error | null) => void) {
// `_destroy` is now necessary because `cancel()` aborts `cancelSignal`,
// which aborts the underlying HTTP `response.body` stream with an
// `AbortError` that `stream.pipeline` forwards to `this.destroy(err)`.
// Before, the inherited `Transform._destroy` passed `err` directly to
// `callback(err)`, causing `StreamArrayParser` to emit a spurious `'error'`
// event even after an intentional `cancel()`. Now, it passes `null` when
// `this.cancelRequested` is true to suppress cancellation abort errors
// while still forwarding genuine errors when not cancelled.
callback(this.cancelRequested ? null : err);
}

Comment on lines +156 to +167

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Generated] Override StreamArrayParser._destroy(err, callback) (and document why _destroy is now necessary): when cancel() aborts cancelSignal, the underlying HTTP response.body stream aborts with an AbortError that stream.pipeline forwards into this.destroy(err). Previously, the inherited Transform._destroy passed err straight to callback(err), causing StreamArrayParser to emit a spurious 'error' event even after an intentional cancel(). Now, _destroy passes null when this.cancelRequested is true to suppress cancellation abort errors while still forwarding genuine errors when not cancelled.

cancel(): void {
this._done = true;
this.cancelRequested = true;
Expand Down
Loading
Loading