Skip to content

Commit c273d3a

Browse files
committed
Replace noCleanup with killOnTimeout for clearer timeout behavior in SSH operations
1 parent 00072f9 commit c273d3a

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/Ssh/RunParams.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function __construct(
1111
public ?string $dotenv = null,
1212
public bool $nothrow = false,
1313
public ?int $timeout = null,
14-
public bool $noCleanup = false,
14+
public bool $killOnTimeout = true,
1515
public ?int $idleTimeout = null,
1616
public bool $forceOutput = false,
1717
#[\SensitiveParameter]
@@ -22,12 +22,12 @@ public function with(
2222
#[\SensitiveParameter]
2323
?array $secrets = null,
2424
?int $timeout = null,
25-
?bool $noCleanup = null,
25+
?bool $killOnTimeout = null,
2626
): self {
2727
$params = clone $this;
2828
$params->secrets = array_merge($params->secrets ?? [], $secrets ?? []);
2929
$params->timeout = $timeout ?? $params->timeout;
30-
$params->noCleanup = $noCleanup ?? $params->noCleanup;
30+
$params->killOnTimeout = $killOnTimeout ?? $params->killOnTimeout;
3131
return $params;
3232
}
3333
}

src/Ssh/SshClient.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ 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-
// 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) {
79+
// Cleanup runs pass killOnTimeout: false so a timeout here can't
80+
// recurse, and cleanup failures must not mask the timeout, so
81+
// swallow them.
82+
if ($params->killOnTimeout) {
8283
try {
8384
$pid = trim($this->run(
8485
$host,
8586
"ps x | grep $shellId | grep -v grep | awk '{print \$1}'",
86-
$params->with(timeout: 10, noCleanup: true),
87+
$params->with(timeout: 10, killOnTimeout: false),
8788
));
8889
if ($pid !== '') {
8990
// Minus before pid means all processes in this group.
90-
$this->run($host, "kill -9 -$pid", $params->with(timeout: 20, noCleanup: true));
91+
$this->run($host, "kill -9 -$pid", $params->with(timeout: 20, killOnTimeout: false));
9192
}
9293
} catch (\Throwable) {
9394
// The shell may have already exited, or `ps`/`kill` may be

0 commit comments

Comments
 (0)