@@ -530,29 +530,34 @@ export class V3 {
530530 await Promise . all ( instances . map ( ( i ) => i . _immediateShutdown ( reason ) ) ) ;
531531 } ;
532532
533- const handleSignal = async ( signal : string ) => {
533+ process . once ( "SIGINT" , ( ) => {
534534 v3Logger ( {
535535 category : "v3" ,
536- message : ` ${ signal } : initiating shutdown` ,
536+ message : "SIGINT : initiating shutdown" ,
537537 level : 0 ,
538538 } ) ;
539-
540- // In API mode, let the server handle cleanup - don't close locally
541539 for ( const instance of V3 . _instances ) {
542540 if ( instance . apiClient ) {
543- const timeout = new Promise ( ( r ) => setTimeout ( r , 5000 ) ) ;
544- await Promise . race ( [
545- instance . apiClient . end ( ) . catch ( ( ) => { } ) ,
546- timeout ,
547- ] ) ;
541+ void instance . apiClient . end ( ) ;
548542 return ;
549543 }
550544 }
551- await shutdownAllImmediate ( `signal ${ signal } ` ) ;
552- } ;
553-
554- process . once ( "SIGINT" , ( ) => void handleSignal ( "SIGINT" ) ) ;
555- process . once ( "SIGTERM" , ( ) => void handleSignal ( "SIGTERM" ) ) ;
545+ void shutdownAllImmediate ( "signal SIGINT" ) ;
546+ } ) ;
547+ process . once ( "SIGTERM" , ( ) => {
548+ v3Logger ( {
549+ category : "v3" ,
550+ message : "SIGTERM: initiating shutdown" ,
551+ level : 0 ,
552+ } ) ;
553+ for ( const instance of V3 . _instances ) {
554+ if ( instance . apiClient ) {
555+ void instance . apiClient . end ( ) ;
556+ return ;
557+ }
558+ }
559+ void shutdownAllImmediate ( "signal SIGTERM" ) ;
560+ } ) ;
556561 process . once ( "uncaughtException" , ( err : unknown ) => {
557562 v3Logger ( {
558563 category : "v3" ,
0 commit comments