fix(cloudflare): drop 10s timeout from tunnel health check command

Remove the explicit 10-second timeout from the cloudflared health check so
it uses the default remote process timeout. Add a feature test confirming
the health check runs with sudo on non-root servers, and that the server is
marked as using a Cloudflare tunnel with its IP set to the SSH domain.
This commit is contained in:
Andras Bacsai
2026-10-15 22:31:25 +02:00
parent 783a103d97
commit bd87baa690
2 changed files with 50 additions and 1 deletions
@@ -26,7 +26,7 @@ class CloudflareTunnelChangedNotification
for ($i = 1; $i <= $attempts; $i++) {
\Log::debug("Cloudflare health check attempt {$i}/{$attempts}", ['server_id' => $server_id]);
$result = instant_remote_process_with_timeout(['docker inspect coolify-cloudflared | jq -e ".[0].State.Health.Status == \"healthy\""'], $this->server, false, 10);
$result = instant_remote_process_with_timeout(['docker inspect coolify-cloudflared | jq -e ".[0].State.Health.Status == \"healthy\""'], $this->server, false);
if (blank($result)) {
\Log::debug("Cloudflare Tunnels container not found on attempt {$i}", ['server_id' => $server_id]);
@@ -0,0 +1,49 @@
<?php
use App\Events\CloudflareTunnelChanged;
use App\Listeners\CloudflareTunnelChangedNotification;
use App\Models\InstanceSettings;
use App\Models\PrivateKey;
use App\Models\Server;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Sleep;
uses(RefreshDatabase::class);
beforeEach(function () {
Server::flushIdentityMap();
InstanceSettings::forceCreate(['id' => 0]);
Storage::fake('ssh-keys');
Storage::fake('ssh-mux');
config()->set('constants.ssh.max_retries', 1);
config()->set('constants.ssh.mux_enabled', false);
$user = User::factory()->create();
$team = $user->teams()->first();
$this->server = Server::factory()->create([
'team_id' => $team->id,
'user' => 'ubuntu',
'private_key_id' => PrivateKey::factory()->create(['team_id' => $team->id])->id,
]);
});
it('uses sudo for the health check on a non-root server', function () {
Event::fake();
Sleep::fake();
Process::fake([
'*sudo docker inspect coolify-cloudflared*' => Process::result(output: 'true'),
'*' => Process::result(errorOutput: 'permission denied while trying to connect to the Docker API', exitCode: 1),
]);
(new CloudflareTunnelChangedNotification)->handle(new CloudflareTunnelChanged([
'server_id' => $this->server->id,
'ssh_domain' => 'ssh.example.com',
]));
expect($this->server->settings->refresh()->is_cloudflare_tunnel)->toBeTruthy()
->and($this->server->refresh()->ip)->toBe('ssh.example.com');
});