8000 Prevent calling `.abort()` on a destroyed request · sindresorhus/got@63c1b72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63c1b72

Browse files
committed
Prevent calling .abort() on a destroyed request
1 parent 3da16e0 commit 63c1b72

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

source/core/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,12 +1447,14 @@ export default class Request extends Duplex implements RequestEvents<Request> {
14471447

14481448
_destroy(error: Error | null, callback: (error: Error | null) => void): void {
14491449
if (kRequest in this) {
1450-
// TODO: Remove the next `if` when https://github.com/nodejs/node/issues/32851 gets fixed
1451-
if (!(this[kResponse]?.complete)) {
1450+
// TODO: Remove the next `if` when these get fixed:
1451+
// - https://github.com/nodejs/node/issues/32851
1452+
// - https://github.com/nock/nock/issues/1981
1453+
if (!this[kResponse]?.complete && !this[kRequest]?.destroyed) {
14521454
this[kRequest]!.abort();
14531455
}
14541456
} else {
1455-
this.once('finalized', (): void => {
1457+
this.prependOnceListener('finalized', (): void => {
14561458
if (kRequest in this) {
14571459
this[kRequest]!.abort();
14581460
}

source/core/utils/timed-out.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ export default (request: ClientRequest, delays: Delays, options: TimedOutOptions
6868
const {host, hostname} = options;
6969

7070
const timeoutHandler = (delay: number, event: string): void => {
71-
if (request.socket) {
72-
(request.socket as any)._hadError = true;
73-
}
74-
7571
request.destroy(new TimeoutError(delay, event));
7672
};
7773

0 commit comments

Comments
 (0)
0