@@ -346,11 +346,9 @@ async function handleChatCompletionsWithBudget(
346346 : ac . signal ;
347347 let detachReq : ( ( ) => void ) | undefined ;
348348 if ( typeof AbortSignal . any !== "function" && ! combinedSignal . aborted ) {
349- const acAbort = ( ) => { } ;
350349 const onReqAbort = ( ) => {
351350 try { ( ac as unknown as { abort : ( r ?: unknown ) => void } ) . abort ( req . signal . reason ) ; } catch { /* noop */ }
352351 } ;
353- void acAbort ;
354352 req . signal . addEventListener ( "abort" , onReqAbort , { once : true } ) ;
355353 detachReq = ( ) => req . signal . removeEventListener ( "abort" , onReqAbort ) ;
356354 }
@@ -677,8 +675,9 @@ async function handleChatCompletionsWithBudget(
677675 }
678676 }
679677 let jsonText : string ;
678+ let jsonReader : ReadableStreamDefaultReader < Uint8Array > | null = null ;
680679 try {
681- const reader = response . body ? response . body . getReader ( ) : null ;
680+ const reader = response . body ? ( jsonReader = response . body . getReader ( ) ) : null ;
682681 if ( ! reader ) {
683682 jsonText = await response . text ( ) ;
684683 translatorBudget . chargeRetained ( new TextEncoder ( ) . encode ( jsonText ) . byteLength , { kind : "request_copies" } ) ;
@@ -700,6 +699,9 @@ async function handleChatCompletionsWithBudget(
700699 jsonText = new TextDecoder ( ) . decode ( merged ) ;
701700 }
702701 } catch ( err ) {
702+ if ( jsonReader ) {
703+ try { void jsonReader . cancel ( ) . catch ( ( ) => { } ) ; } catch { /* noop */ }
704+ }
703705 if ( isTranslatorBudgetExceededError ( err ) ) {
704706 cleanup ( ) ;
705707 finishRequestAttempt ( attempt , 413 , Date . now ( ) - ( logCtx . activeAttemptStartedAt ?? Date . now ( ) ) ) ;
0 commit comments