Skip to content

Commit

Permalink
Prevent calling .abort() on a destroyed request
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Apr 26, 2020
1 parent 3da16e0 commit 63c1b72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 5 additions & 3 deletions source/core/index.ts
Expand Up @@ -1447,12 +1447,14 @@ export default class Request extends Duplex implements RequestEvents<Request> {

_destroy(error: Error | null, callback: (error: Error | null) => void): void {
if (kRequest in this) {
// TODO: Remove the next `if` when https://github.com/nodejs/node/issues/32851 gets fixed
if (!(this[kResponse]?.complete)) {
// TODO: Remove the next `if` when these get fixed:
// - https://github.com/nodejs/node/issues/32851
// - https://github.com/nock/nock/issues/1981
if (!this[kResponse]?.complete && !this[kRequest]?.destroyed) {
this[kRequest]!.abort();
}
} else {
this.once('finalized', (): void => {
this.prependOnceListener('finalized', (): void => {
if (kRequest in this) {
this[kRequest]!.abort();
}
Expand Down
4 changes: 0 additions & 4 deletions source/core/utils/timed-out.ts
Expand Up @@ -68,10 +68,6 @@ export default (request: ClientRequest, delays: Delays, options: TimedOutOptions
const {host, hostname} = options;

const timeoutHandler = (delay: number, event: string): void => {
if (request.socket) {
(request.socket as any)._hadError = true;
}

request.destroy(new TimeoutError(delay, event));
};

Expand Down

0 comments on commit 63c1b72

Please sign in to comment.