@@ -46,7 +46,7 @@ public function run(Host $host, string $command, RunParams $params): string
4646 if ($ this ->output ->isDebug ()) {
4747 $ sshString = $ ssh [0 ];
4848 for ($ i = 1 ; $ i < count ($ ssh ); $ i ++) {
49- $ sshString .= ' ' . \Deployer \quote ((string ) $ ssh [$ i ]);
49+ $ sshString .= ' ' . \Deployer \quote ((string )$ ssh [$ i ]);
5050 }
5151 $ this ->output ->writeln ("[ $ host] $ sshString " );
5252 }
@@ -76,9 +76,24 @@ public function run(Host $host, string $command, RunParams $params): string
7676 $ process ->run ($ callback );
7777 } catch (ProcessTimedOutException $ exception ) {
7878 // Let's try to kill all processes started by this command.
79- $ pid = $ this ->run ($ host , "ps x | grep $ shellId | grep -v grep | awk '{print \$1}' " , $ params ->with (timeout: 10 ));
80- // Minus before pid means all processes in this group.
81- $ this ->run ($ host , "kill -9 - $ pid " , $ params ->with (timeout: 20 ));
79+ // Cleanup runs pass noCleanup so a timeout here can't recurse,
80+ // and cleanup failures must not mask the timeout, so swallow them.
81+ if (!$ params ->noCleanup ) {
82+ try {
83+ $ pid = trim ($ this ->run (
84+ $ host ,
85+ "ps x | grep $ shellId | grep -v grep | awk '{print \$1}' " ,
86+ $ params ->with (timeout: 10 , noCleanup: true ),
87+ ));
88+ if ($ pid !== '' ) {
89+ // Minus before pid means all processes in this group.
90+ $ this ->run ($ host , "kill -9 - $ pid " , $ params ->with (timeout: 20 , noCleanup: true ));
91+ }
92+ } catch (\Throwable ) {
93+ // The shell may have already exited, or `ps`/`kill` may be
94+ // restricted. Either way, the timeout is the real error.
95+ }
96+ }
8297 throw new TimeoutException (
8398 $ command ,
8499 $ exception ->getExceededTimeout (),
0 commit comments