@@ -395,9 +395,15 @@ export class HttpClient {
395395 timeoutSignal : AbortSignal ,
396396 callerSignal : AbortSignal | undefined ,
397397 requestId : string ,
398+ effectiveSignal : AbortSignal = timeoutSignal ,
398399 ) : void {
399400 if ( isAbortError ( err ) || isTimeoutError ( err ) ) {
400- if ( timeoutSignal . aborted && ( callerSignal == null || ! callerSignal . aborted ) ) {
401+ const timeoutWon =
402+ timeoutSignal . aborted &&
403+ ( callerSignal == null ||
404+ ! callerSignal . aborted ||
405+ effectiveSignal . reason === timeoutSignal . reason ) ;
406+ if ( timeoutWon ) {
401407 throw new RequestTimeoutError ( this . requestTimeoutMs , requestId ) ;
402408 }
403409 throw err ;
@@ -451,7 +457,7 @@ export class HttpClient {
451457 // the caller hadn't already aborted, surface a clear RequestTimeoutError.
452458 // A timeout/abort during the fetch itself: classify it (RequestTimeoutError
453459 // when our deadline fired; otherwise rethrow the caller's abort unmodified).
454- this . rethrowIfAbort ( err , timeoutSignal , options . signal , requestId ) ;
460+ this . rethrowIfAbort ( err , timeoutSignal , options . signal , requestId , effectiveSignal ) ;
455461 // If a RequestTimeoutError already propagated from somewhere (e.g. from a
456462 // nested call or from a test-injected fetchImpl), pass it through unchanged
457463 // rather than re-wrapping it as a TransportError.
@@ -500,7 +506,7 @@ export class HttpClient {
500506 return { body : ( await response . json ( ) ) as T , requestId, status : response . status } ;
501507 } catch ( err ) {
502508 // A timeout/abort can fire mid-body-read (headers received, stream stalls).
503- this . rethrowIfAbort ( err , timeoutSignal , options . signal , requestId ) ;
509+ this . rethrowIfAbort ( err , timeoutSignal , options . signal , requestId , effectiveSignal ) ;
504510 throw err ;
505511 }
506512 }
@@ -511,7 +517,7 @@ export class HttpClient {
511517 } catch ( err ) {
512518 // safeReadJson rethrows aborts/timeouts (it swallows only non-abort parse
513519 // errors), so a timeout fired mid-body-read on a non-OK response lands here.
514- this . rethrowIfAbort ( err , timeoutSignal , options . signal , requestId ) ;
520+ this . rethrowIfAbort ( err , timeoutSignal , options . signal , requestId , effectiveSignal ) ;
515521 throw err ;
516522 }
517523
0 commit comments