fix: do not handle write errors after request is aborted (#28682)

This fixes a flake on linux CI which started recently where the "write"
promise is being rejected after the request has been aborted /
cancelled.  In this case we should drop the error to the floor but
instead we pass it down the stack where it eventually emits a now
unhandled error event.

Example failure: https://app.circleci.com/pipelines/github/electron/electron/38072/workflows/c1faf19b-aa41-4f99-a564-165729222859/jobs/838813

Verified fix by running the test that caused it 10000 times before fix
and 10000 times after.  ~50 failures before, 0 after.
This commit is contained in:
Samuel Attard 2021-04-19 06:50:14 -07:00 committed by GitHub
parent 484931bba2
commit b8c2481edb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,6 +188,11 @@ class ChunkedBodyStream extends Writable {
this._downstream = pipe;
if (this._pendingChunk) {
const doneWriting = (maybeError: Error | void) => {
// If the underlying request has been aborted, we honeslty don't care about the error
// all work should cease as soon as we abort anyway, this error is probably a
// "mojo pipe disconnected" error (code=9)
if (this._clientRequest._aborted) return;
const cb = this._pendingCallback!;
delete this._pendingCallback;
delete this._pendingChunk;