Skip to content

Commit 3f4ef9a

Browse files
authored
refactor: simplify signal handling (#3362)
1 parent 0455e06 commit 3f4ef9a

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

lib/api/api-request.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ class RequestHandler extends AsyncResource {
7777
} else if (this.abort) {
7878
this.abort(this.reason)
7979
}
80-
81-
if (this.removeAbortListener) {
82-
this.res?.off('close', this.removeAbortListener)
83-
this.removeAbortListener()
84-
this.removeAbortListener = null
85-
}
8680
})
8781
}
8882
}
@@ -127,6 +121,7 @@ class RequestHandler extends AsyncResource {
127121

128122
if (this.removeAbortListener) {
129123
res.on('close', this.removeAbortListener)
124+
this.removeAbortListener = null
130125
}
131126

132127
this.callback = null
@@ -183,7 +178,6 @@ class RequestHandler extends AsyncResource {
183178
}
184179

185180
if (this.removeAbortListener) {
186-
res?.off('close', this.removeAbortListener)
187181
this.removeAbortListener()
188182
this.removeAbortListener = null
189183
}

lib/core/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function addAbortListener (signal, listener) {
518518
signal.addEventListener('abort', listener, { once: true })
519519
return () => signal.removeEventListener('abort', listener)
520520
}
521-
signal.addListener('abort', listener)
521+
signal.once('abort', listener)
522522
return () => signal.removeListener('abort', listener)
523523
}
524524

0 commit comments

Comments
 (0)