@@ -118,6 +118,14 @@ const PREFERRED_SIGNAL_NAMES = [
118118 "SIGEMT" ,
119119 "SIGINFO" ,
120120] as const ;
121+ const NON_TERMINATING_SIGNALS = new Set ( [
122+ "0" ,
123+ "SIGCHLD" ,
124+ "SIGCONT" ,
125+ "SIGSTOP" ,
126+ "SIGURG" ,
127+ "SIGWINCH" ,
128+ ] ) ;
121129const NON_CANONICAL_SIGNAL_NAMES = new Set ( [
122130 "SIGCLD" ,
123131 "SIGIOT" ,
@@ -418,7 +426,10 @@ export class NativeSidecarKernelProxy {
418426 liveProcesses . map ( ( entry ) => this . signalProcess ( entry , 15 ) ) ,
419427 ) ;
420428
421- await this . client . disposeVm ( this . session , this . vm ) . catch ( ( ) => { } ) ;
429+ await Promise . race ( [
430+ this . client . disposeVm ( this . session , this . vm ) ,
431+ new Promise < void > ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ,
432+ ] ) . catch ( ( ) => { } ) ;
422433 for ( const entry of liveProcesses ) {
423434 if ( entry . exitCode === null ) {
424435 // The sidecar dispose path already performs TERM/KILL escalation for any
@@ -679,13 +690,19 @@ export class NativeSidecarKernelProxy {
679690 }
680691 entry . pendingKillSignal = signal ;
681692 void entry . startPromise . then ( async ( ) => {
682- if ( entry . exitCode !== null || entry . pendingKillSignal === null ) {
693+ if ( entry . pendingKillSignal === null ) {
683694 return ;
684695 }
685696 const pendingSignal = entry . pendingKillSignal ;
686697 entry . pendingKillSignal = null ;
687698 await this . signalProcess ( entry , pendingSignal ) ;
688699 } ) ;
700+ if (
701+ ( signal === 9 || signal === 15 ) &&
702+ entry . exitCode === null
703+ ) {
704+ this . finishProcess ( entry , 128 + signal ) ;
705+ }
689706 } ,
690707 wait : async ( ) => {
691708 const exitCode = await this . waitForTrackedProcess ( entry ) ;
@@ -1683,14 +1700,34 @@ export class NativeSidecarKernelProxy {
16831700 entry : TrackedProcessEntry ,
16841701 signal : number ,
16851702 ) : Promise < void > {
1686- await this . signalRefreshes . get ( entry . pid ) ;
1703+ const sidecarSignal = toSidecarSignalName ( signal ) ;
1704+ let timedOut = false ;
1705+ const killPromise = this . client . killProcess (
1706+ this . session ,
1707+ this . vm ,
1708+ entry . processId ,
1709+ sidecarSignal ,
1710+ ) ;
16871711 try {
1688- await this . client . killProcess (
1689- this . session ,
1690- this . vm ,
1691- entry . processId ,
1692- toSidecarSignalName ( signal ) ,
1693- ) ;
1712+ await Promise . race ( [
1713+ killPromise ,
1714+ new Promise < void > ( ( resolve ) =>
1715+ setTimeout ( ( ) => {
1716+ timedOut = true ;
1717+ resolve ( ) ;
1718+ } , 1000 ) ,
1719+ ) ,
1720+ ] ) ;
1721+ if ( timedOut ) {
1722+ void killPromise . catch ( ( ) => { } ) ;
1723+ }
1724+ if (
1725+ entry . exitCode === null &&
1726+ ! NON_TERMINATING_SIGNALS . has ( sidecarSignal ) &&
1727+ ( entry . driver === "wasmvm" || timedOut )
1728+ ) {
1729+ this . finishProcess ( entry , 128 + signal ) ;
1730+ }
16941731 } catch ( error ) {
16951732 if ( isNoSuchProcessError ( error ) || isUnknownVmError ( error ) ) {
16961733 return ;
0 commit comments