File tree Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @smithy/fetch-http-handler " : patch
3
+ " @smithy/node-http-handler " : patch
4
+ ---
5
+
6
+ remove abort signal event listeners after request completion
Original file line number Diff line number Diff line change @@ -127,6 +127,8 @@ export class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
127
127
requestOptions . keepalive = keepAlive ;
128
128
}
129
129
130
+ let removeSignalEventListener = null as null | ( ( ) => void ) ;
131
+
130
132
const fetchRequest = new Request ( url , requestOptions ) ;
131
133
const raceOfPromises = [
132
134
fetch ( fetchRequest ) . then ( ( response ) => {
@@ -173,15 +175,17 @@ export class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
173
175
} ;
174
176
if ( typeof ( abortSignal as AbortSignal ) . addEventListener === "function" ) {
175
177
// preferred.
176
- ( abortSignal as AbortSignal ) . addEventListener ( "abort" , onAbort ) ;
178
+ const signal = abortSignal as AbortSignal ;
179
+ signal . addEventListener ( "abort" , onAbort , { once : true } ) ;
180
+ removeSignalEventListener = ( ) => signal . removeEventListener ( "abort" , onAbort ) ;
177
181
} else {
178
182
// backwards compatibility
179
183
abortSignal . onabort = onAbort ;
180
184
}
181
185
} )
182
186
) ;
183
187
}
184
- return Promise . race ( raceOfPromises ) ;
188
+ return Promise . race ( raceOfPromises ) . finally ( removeSignalEventListener ) ;
185
189
}
186
190
187
191
updateHttpClientConfig ( key : keyof FetchHttpHandlerConfig , value : FetchHttpHandlerConfig [ typeof key ] ) : void {
Original file line number Diff line number Diff line change @@ -252,7 +252,9 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
252
252
} ;
253
253
if ( typeof ( abortSignal as AbortSignal ) . addEventListener === "function" ) {
254
254
// preferred.
255
- ( abortSignal as AbortSignal ) . addEventListener ( "abort" , onAbort ) ;
255
+ const signal = abortSignal as AbortSignal ;
256
+ signal . addEventListener ( "abort" , onAbort , { once : true } ) ;
257
+ req . once ( "close" , ( ) => signal . removeEventListener ( "abort" , onAbort ) ) ;
256
258
} else {
257
259
// backwards compatibility
258
260
abortSignal . onabort = onAbort ;
Original file line number Diff line number Diff line change @@ -189,7 +189,9 @@ export class NodeHttp2Handler implements HttpHandler<NodeHttp2HandlerOptions> {
189
189
} ;
190
190
if ( typeof ( abortSignal as AbortSignal ) . addEventListener === "function" ) {
191
191
// preferred.
192
- ( abortSignal as AbortSignal ) . addEventListener ( "abort" , onAbort ) ;
192
+ const signal = abortSignal as AbortSignal ;
193
+ signal . addEventListener ( "abort" , onAbort , { once : true } ) ;
194
+ req . once ( "close" , ( ) => signal . removeEventListener ( "abort" , onAbort ) ) ;
193
195
} else {
194
196
// backwards compatibility
195
197
abortSignal . onabort = onAbort ;
You can’t perform that action at this time.
0 commit comments