@@ -499,7 +499,7 @@ export class SFCNodes {
499499 controller : AbortController ,
500500 ) : Promise < Response > {
501501 const { signal, method, ...options } = init || { } ;
502- const abort = controller . abort . bind ( controller ) ;
502+ const abort = this . _makeAbort ( controller ) ;
503503 if ( signal ) signal . addEventListener ( 'abort' , abort , { once : true } ) ;
504504
505505 const timeout = setTimeout ( abort , ms ) ;
@@ -525,6 +525,7 @@ export class SFCNodes {
525525 return await this . fetch . call ( undefined , url , fetchOptions ) ;
526526 } finally {
527527 clearTimeout ( timeout ) ;
528+ if ( signal ) signal . removeEventListener ( 'abort' , abort ) ;
528529 }
529530 }
530531
@@ -669,6 +670,12 @@ export class SFCNodes {
669670 return headers . values ;
670671 }
671672
673+ private _makeAbort ( controller : AbortController ) {
674+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
675+ // would capture all request options, and cause a memory leak.
676+ return ( ) => controller . abort ( ) ;
677+ }
678+
672679 private buildBody ( { options : { body, headers : rawHeaders } } : { options : FinalRequestOptions } ) : {
673680 bodyHeaders : HeadersLike ;
674681 body : BodyInit | undefined ;
0 commit comments