@@ -149,6 +149,45 @@ describe("ssh command", () => {
149149 } ) . pipe ( Effect . provide ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ) ,
150150 ) ;
151151
152+ it . live . skipIf ( HostProcess . Platform . defaultValue ( ) === "win32" ) (
153+ "a timed-out command leaves no helper running that ignored SIGTERM" ,
154+ ( ) =>
155+ Effect . gen ( function * ( ) {
156+ const nativeSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
157+ // Stands in for ssh and a ProxyCommand: ssh exits on SIGTERM, the proxy ignores it.
158+ const spawner = ChildProcessSpawner . make ( ( command ) =>
159+ nativeSpawner . spawn (
160+ ChildProcess . make (
161+ process . execPath ,
162+ [
163+ "-e" ,
164+ `const proxy = require("node:child_process").spawn("sh", ["-c", "trap '' TERM; exec sleep 60"], { stdio: "ignore" });
165+ process.stdout.write(proxy.pid + "\\n");
166+ setInterval(() => {}, 1000);` ,
167+ ] ,
168+ command . _tag === "StandardCommand" ? command . options : { } ,
169+ ) ,
170+ ) ,
171+ ) ;
172+ const failure = yield * runSshCommand (
173+ { alias : "synthetic-fixture" , hostname : "synthetic-fixture" , username : null , port : null } ,
174+ { timeoutMs : 1_000 , keepErrorOutputTail : true } ,
175+ ) . pipe (
176+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
177+ Effect . flip ,
178+ ) ;
179+ assert . instanceOf ( failure , SshCommandError ) ;
180+ assert . equal ( failure . message , "SSH command timed out after 1000ms." ) ;
181+ const proxyPid = Number ( failure . stdout ?. trim ( ) ) ;
182+ assert . isTrue ( Number . isSafeInteger ( proxyPid ) && proxyPid > 1 ) ;
183+ const state = ( yield * nativeSpawner . string (
184+ ChildProcess . make ( "ps" , [ "-p" , String ( proxyPid ) , "-o" , "stat=" ] ) ,
185+ ) ) . trim ( ) ;
186+ if ( state !== "" && ! state . startsWith ( "Z" ) ) process . kill ( proxyPid , "SIGKILL" ) ;
187+ assert . isTrue ( state === "" || state . startsWith ( "Z" ) , `proxy still running (${ state } )` ) ;
188+ } ) . pipe ( Effect . provide ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ) ,
189+ ) ;
190+
152191 it . live ( "enables server-alive checks for long remote commands" , ( ) =>
153192 Effect . gen ( function * ( ) {
154193 // Ask OpenSSH for its effective configuration without opening a connection.
0 commit comments