@@ -505,7 +505,7 @@ export class Conductor {
505505 controller : AbortController ,
506506 ) : Promise < Response > {
507507 const { signal, method, ...options } = init || { } ;
508- const abort = controller . abort . bind ( controller ) ;
508+ const abort = this . _makeAbort ( controller ) ;
509509 if ( signal ) signal . addEventListener ( 'abort' , abort , { once : true } ) ;
510510
511511 const timeout = setTimeout ( abort , ms ) ;
@@ -531,6 +531,7 @@ export class Conductor {
531531 return await this . fetch . call ( undefined , url , fetchOptions ) ;
532532 } finally {
533533 clearTimeout ( timeout ) ;
534+ if ( signal ) signal . removeEventListener ( 'abort' , abort ) ;
534535 }
535536 }
536537
@@ -675,6 +676,12 @@ export class Conductor {
675676 return headers . values ;
676677 }
677678
679+ private _makeAbort ( controller : AbortController ) {
680+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
681+ // would capture all request options, and cause a memory leak.
682+ return ( ) => controller . abort ( ) ;
683+ }
684+
678685 private buildBody ( { options : { body, headers : rawHeaders } } : { options : FinalRequestOptions } ) : {
679686 bodyHeaders : HeadersLike ;
680687 body : BodyInit | undefined ;
0 commit comments