Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: getcontainer status should timeout after 30s

Andras Bacsaib7d18fc28cfc
diff --git a/app/Models/Server.php b/app/Models/Server.php
index 8d11e23a93..cc6bff2cf8 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -656,9 +656,9 @@ $schema://$host {
$containers = collect([]);
$containerReplicates = collect([]);
if ($this->isSwarm()) {
- $containers = instant_remote_process(["docker service inspect $(docker service ls -q) --format '{{json .}}'"], $this, false);
+ $containers = instant_remote_process_with_timeout(["docker service inspect $(docker service ls -q) --format '{{json .}}'"], $this, false);
$containers = format_docker_command_output_to_json($containers);
- $containerReplicates = instant_remote_process(["docker service ls --format '{{json .}}'"], $this, false);
+ $containerReplicates = instant_remote_process_with_timeout(["docker service ls --format '{{json .}}'"], $this, false);
if ($containerReplicates) {
$containerReplicates = format_docker_command_output_to_json($containerReplicates);
foreach ($containerReplicates as $containerReplica) {
@@ -682,7 +682,7 @@ $schema://$host {
}
}
} else {
- $containers = instant_remote_process(["docker container inspect $(docker container ls -aq) --format '{{json .}}'"], $this, false);
+ $containers = instant_remote_process_with_timeout(["docker container inspect $(docker container ls -aq) --format '{{json .}}'"], $this, false);
$containers = format_docker_command_output_to_json($containers);
$containerReplicates = collect([]);
}
diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php
index c7dd2cb83f..d1cb93d9af 100644
--- a/bootstrap/helpers/remoteProcess.php
+++ b/bootstrap/helpers/remoteProcess.php
@@ -71,6 +71,31 @@ function instant_scp(string $source, string $dest, Server $server, $throwError =
return $output === 'null' ? null : $output;
}
+function instant_remote_process_with_timeout(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false): ?string
+{
+ $command = $command instanceof Collection ? $command->toArray() : $command;
+ if ($server->isNonRoot() && ! $no_sudo) {
+ $command = parseCommandsByLineForSudo(collect($command), $server);
+ }
+ $command_string = implode("\n", $command);
+
+ // $start_time = microtime(true);
+ $sshCommand = SshMultiplexingHelper::generateSshCommand($server, $command_string);
+ $process = Process::timeout(30)->run($sshCommand);
+ // $end_time = microtime(true);
+
+ // $execution_time = ($end_time - $start_time) * 1000; // Convert to milliseconds
+ // ray('SSH command execution time:', $execution_time.' ms')->orange();
+
+ $output = trim($process->output());
+ $exitCode = $process->exitCode();
+
+ if ($exitCode !== 0) {
+ return $throwError ? excludeCertainErrors($process->errorOutput(), $exitCode) : null;
+ }
+
+ return $output === 'null' ? null : $output;
+}
function instant_remote_process(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false): ?string
{
$command = $command instanceof Collection ? $command->toArray() : $command;