Skip to content

Commit

Permalink
Fix hanging promise on aborted requests on Node v14.3.0 (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giotino committed May 31, 2020
1 parent 2c8fe19 commit 2ccc4c2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions source/core/index.ts
Expand Up @@ -1057,10 +1057,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
});

response.once('aborted', () => {
if (this.aborted) {
return;
}

this._beforeError(new ReadError({
name: 'Error',
message: 'The server aborted the pending request'
Expand Down Expand Up @@ -1462,6 +1458,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}

async _beforeError(error: Error): Promise<void> {
if (this.destroyed) {
return;
}

this[kStopReading] = true;

if (!(error instanceof RequestError)) {
Expand All @@ -1488,10 +1488,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
error = new RequestError(error_.message, error_, this);
}

// This is a workaround for https://github.com/nodejs/node/issues/33335
if (!this.destroyed) {
this.destroy(error);
}
this.destroy(error);
}

_read(): void {
Expand Down

0 comments on commit 2ccc4c2

Please sign in to comment.