File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -210,8 +210,30 @@ export class StdioClientTransport implements Transport {
210210 }
211211
212212 async close ( ) : Promise < void > {
213- this . _abortController . abort ( ) ;
214- this . _process = undefined ;
213+ if ( this . _process ) {
214+ const processToClose = this . _process ;
215+ this . _process = undefined ;
216+
217+ const closePromise = new Promise < void > ( resolve => {
218+ processToClose . once ( 'close' , ( ) => {
219+ resolve ( ) ;
220+ } ) ;
221+ } ) ;
222+
223+ this . _abortController . abort ( ) ;
224+
225+ // waits the underlying process to exit cleanly otherwise after 1s kills it
226+ await Promise . race ( [ closePromise , new Promise ( resolve => setTimeout ( resolve , 1_000 ) . unref ( ) ) ] ) ;
227+
228+ if ( processToClose . exitCode === null ) {
229+ try {
230+ processToClose . kill ( 'SIGKILL' ) ;
231+ } catch {
232+ // we did our best
233+ }
234+ }
235+ }
236+
215237 this . _readBuffer . clear ( ) ;
216238 }
217239
You can’t perform that action at this time.
0 commit comments