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> {
127127 requestOptions . keepalive = keepAlive ;
128128 }
129129
130+ let removeSignalEventListener = null as null | ( ( ) => void ) ;
131+
130132 const fetchRequest = new Request ( url , requestOptions ) ;
131133 const raceOfPromises = [
132134 fetch ( fetchRequest ) . then ( ( response ) => {
@@ -173,15 +175,17 @@ export class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
173175 } ;
174176 if ( typeof ( abortSignal as AbortSignal ) . addEventListener === "function" ) {
175177 // 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 ) ;
177181 } else {
178182 // backwards compatibility
179183 abortSignal . onabort = onAbort ;
180184 }
181185 } )
182186 ) ;
183187 }
184- return Promise . race ( raceOfPromises ) ;
188+ return Promise . race ( raceOfPromises ) . finally ( removeSignalEventListener ) ;
185189 }
186190
187191 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
252252 } ;
253253 if ( typeof ( abortSignal as AbortSignal ) . addEventListener === "function" ) {
254254 // 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 ) ) ;
256258 } else {
257259 // backwards compatibility
258260 abortSignal . onabort = onAbort ;
Original file line number Diff line number Diff line change @@ -189,7 +189,9 @@ export class NodeHttp2Handler implements HttpHandler<NodeHttp2HandlerOptions> {
189189 } ;
190190 if ( typeof ( abortSignal as AbortSignal ) . addEventListener === "function" ) {
191191 // 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 ) ) ;
193195 } else {
194196 // backwards compatibility
195197 abortSignal . onabort = onAbort ;
You can’t perform that action at this time.
0 commit comments