@@ -6,6 +6,7 @@ import * as os from "node:os";
66import path from "node:path" ;
77import * as readline from "node:readline" ;
88import moment from "moment" ;
9+ import kill from "tree-kill"
910
1011const require = createRequire ( import . meta. url ) ;
1112const _TOOLKIT_RUN_TIMEOUT_MSECS = 30000 ;
@@ -140,16 +141,7 @@ export function cmd(timeout, ...commands) {
140141 console . debug ( "=> Killing process tree with PID:" , child . pid ) ;
141142 console . debug ( " Command:" , `${ bin } ${ args . join ( " " ) } ` ) ;
142143 if ( ! child . pid ) return ;
143- try {
144- if ( process . platform === "win32" ) {
145- spawn ( "taskkill" , [ "/PID" , child . pid . toString ( ) , "/T" , "/F" ] ) ;
146- } else {
147- // kill entire process group
148- process . kill ( child . pid , "SIGKILL" ) ;
149- }
150- } catch ( err ) {
151- console . debug ( " Error:" , err ) ;
152- }
144+ kill ( child . pid , ( err ) => console . debug ( " Error:" , err ) )
153145 } ;
154146
155147 const timer =
@@ -177,7 +169,7 @@ export function cmd(timeout, ...commands) {
177169 if ( finished ) return ;
178170 finished = true ;
179171 if ( timer ) clearTimeout ( timer ) ;
180-
172+
181173 if ( signal ) {
182174 killTree ( ) ;
183175 reject ( new Error ( `npx terminated by signal ${ signal } ` ) ) ;
@@ -189,7 +181,6 @@ export function cmd(timeout, ...commands) {
189181 reject ( new Error ( `npx failed with exit code ${ code } \n${ stderr } ` ) ) ;
190182 return ;
191183 }
192-
193184 resolve ( stdout ) ;
194185 } ) ;
195186 } ) ;
@@ -562,25 +553,25 @@ export async function toolkitRun(settings, args) {
562553 let stderr = "" ;
563554 let finished = false ;
564555
565- const killTree = ( ) => {
566- if ( ! child . pid ) return ;
567- try {
568- if ( process . platform === "win32" ) {
569- spawn ( "taskkill" , [ "/PID" , child . pid . toString ( ) , "/T" , "/F" ] ) ;
570- } else {
571- // kill entire process group
572- process . kill ( child . pid , "SIGKILL" ) ;
573- }
574- } catch { }
575- } ;
556+ // const killTree = () => {
557+ // if (!child.pid) return;
558+ // try {
559+ // if (process.platform === "win32") {
560+ // spawn("taskkill", ["/PID", child.pid.toString(), "/T", "/F"]);
561+ // } else {
562+ // // kill entire process group
563+ // process.kill(child.pid, "SIGKILL");
564+ // }
565+ // } catch {}
566+ // };
576567
577568 child . stdout . on ( "data" , ( d ) => ( stdout += d . toString ( ) ) ) ;
578569 child . stderr . on ( "data" , ( d ) => ( stderr += d . toString ( ) ) ) ;
579570
580571 child . on ( "error" , ( err ) => {
581572 if ( finished ) return ;
582573 finished = true ;
583- killTree ( ) ;
574+ // killTree();
584575 reject ( err ) ;
585576 } ) ;
586577
@@ -589,13 +580,13 @@ export async function toolkitRun(settings, args) {
589580 finished = true ;
590581
591582 if ( signal ) {
592- killTree ( ) ;
583+ // killTree();
593584 reject ( new Error ( `witnet_toolkit binary terminated by signal ${ signal } ` ) ) ;
594585 return ;
595586 }
596587
597588 if ( code !== 0 ) {
598- killTree ( ) ;
589+ // killTree();
599590 reject ( new Error ( `witnet_toolkit binary failed with exit code ${ code } \n${ stderr } ` ) ) ;
600591 return ;
601592 }
0 commit comments