@@ -486,7 +486,7 @@ export class WarpAPI {
486486 controller : AbortController ,
487487 ) : Promise < Response > {
488488 const { signal, method, ...options } = init || { } ;
489- const abort = controller . abort . bind ( controller ) ;
489+ const abort = this . _makeAbort ( controller ) ;
490490 if ( signal ) signal . addEventListener ( 'abort' , abort , { once : true } ) ;
491491
492492 const timeout = setTimeout ( abort , ms ) ;
@@ -512,6 +512,7 @@ export class WarpAPI {
512512 return await this . fetch . call ( undefined , url , fetchOptions ) ;
513513 } finally {
514514 clearTimeout ( timeout ) ;
515+ if ( signal ) signal . removeEventListener ( 'abort' , abort ) ;
515516 }
516517 }
517518
@@ -656,6 +657,12 @@ export class WarpAPI {
656657 return headers . values ;
657658 }
658659
660+ private _makeAbort ( controller : AbortController ) {
661+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
662+ // would capture all request options, and cause a memory leak.
663+ return ( ) => controller . abort ( ) ;
664+ }
665+
659666 private buildBody ( { options : { body, headers : rawHeaders } } : { options : FinalRequestOptions } ) : {
660667 bodyHeaders : HeadersLike ;
661668 body : BodyInit | undefined ;
0 commit comments