mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(ssh): never disable the SSH command timeout
SSH_COMMAND_TIMEOUT=0 (or an invalid value) removed the time limit of every remote command, and imports could then be marked stale while still running. Use the default of 3600 seconds for values that are not positive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
575a97b6b7
commit
714b09fa24
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
// 0 or an invalid value would remove the time limit of every remote command.
|
||||
$sshCommandTimeout = (int) env('SSH_COMMAND_TIMEOUT', 3600);
|
||||
|
||||
return [
|
||||
'coolify' => [
|
||||
'version' => env('COOLIFY_VERSION') ?: '4.4',
|
||||
@@ -79,7 +82,7 @@ return [
|
||||
'mux_orphan_reap_enabled' => env('SSH_MUX_ORPHAN_REAP_ENABLED', false), // false = dry-run, only log orphans
|
||||
'connection_timeout' => 10,
|
||||
'server_interval' => 20,
|
||||
'command_timeout' => env('SSH_COMMAND_TIMEOUT', 3600),
|
||||
'command_timeout' => $sshCommandTimeout > 0 ? $sshCommandTimeout : 3600,
|
||||
'max_retries' => env('SSH_MAX_RETRIES', 3),
|
||||
'retry_base_delay' => env('SSH_RETRY_BASE_DELAY', 2), // seconds
|
||||
'retry_max_delay' => env('SSH_RETRY_MAX_DELAY', 30), // seconds
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Load config/constants.php with SSH_COMMAND_TIMEOUT set to the given value.
|
||||
*/
|
||||
function sshCommandTimeoutFromEnv(?string $value): mixed
|
||||
{
|
||||
$original = [$_SERVER['SSH_COMMAND_TIMEOUT'] ?? null, $_ENV['SSH_COMMAND_TIMEOUT'] ?? null, getenv('SSH_COMMAND_TIMEOUT')];
|
||||
|
||||
try {
|
||||
if ($value === null) {
|
||||
unset($_SERVER['SSH_COMMAND_TIMEOUT'], $_ENV['SSH_COMMAND_TIMEOUT']);
|
||||
putenv('SSH_COMMAND_TIMEOUT');
|
||||
} else {
|
||||
$_SERVER['SSH_COMMAND_TIMEOUT'] = $_ENV['SSH_COMMAND_TIMEOUT'] = $value;
|
||||
putenv("SSH_COMMAND_TIMEOUT={$value}");
|
||||
}
|
||||
|
||||
return (require config_path('constants.php'))['ssh']['command_timeout'];
|
||||
} finally {
|
||||
[$server, $env, $putenv] = $original;
|
||||
if ($server === null) {
|
||||
unset($_SERVER['SSH_COMMAND_TIMEOUT']);
|
||||
} else {
|
||||
$_SERVER['SSH_COMMAND_TIMEOUT'] = $server;
|
||||
}
|
||||
if ($env === null) {
|
||||
unset($_ENV['SSH_COMMAND_TIMEOUT']);
|
||||
} else {
|
||||
$_ENV['SSH_COMMAND_TIMEOUT'] = $env;
|
||||
}
|
||||
putenv($putenv === false ? 'SSH_COMMAND_TIMEOUT' : "SSH_COMMAND_TIMEOUT={$putenv}");
|
||||
}
|
||||
}
|
||||
|
||||
it('never disables the SSH command timeout', function (?string $value) {
|
||||
expect(sshCommandTimeoutFromEnv($value))->toBe(3600);
|
||||
})->with([
|
||||
'not set' => null,
|
||||
'zero' => '0',
|
||||
'negative' => '-5',
|
||||
'not a number' => 'never',
|
||||
]);
|
||||
|
||||
it('keeps a positive SSH command timeout', function () {
|
||||
expect(sshCommandTimeoutFromEnv('7200'))->toBe(7200);
|
||||
});
|
||||
Reference in New Issue
Block a user