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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(init): keep a detected public IP when the other family's lookup times out
Andras Bacsaif9649d753d5c
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 48aa00a907..719ef26b88 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -46,7 +46,6 @@ use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\ModelNotFoundException;use Illuminate\Database\UniqueConstraintViolationException;-use Illuminate\Process\Pool;use Illuminate\Support\Carbon;use Illuminate\Support\Collection;use Illuminate\Support\Facades\Auth;@@ -2733,15 +2732,21 @@ function get_public_ips(): voidfunction detect_public_ips(array $columns = ['public_ipv4', 'public_ipv6']): array{$versions = array_intersect_key(['public_ipv4' => 4, 'public_ipv6' => 6], array_flip($columns));- $results = Process::concurrently(function (Pool $pool) use ($versions) {- foreach ($versions as $column => $version) {- $pool->as($column)->path(__DIR__)->command("curl -{$version}s https://ifconfig.io");- }- });- $detected = [];+ // Start the lookups together, but wait for each one alone, so a timeout of one family does not discard the other.+ $processes = [];foreach ($versions as $column => $version) {- $ip = trim($results[$column]->output());+ $processes[$column] = Process::path(__DIR__)->start("curl -{$version}s --max-time 10 https://ifconfig.io");+ }++ $detected = [];+ foreach ($processes as $column => $process) {+ try {+ $ip = trim($process->wait()->output());+ } catch (Throwable) {+ continue;+ }+ $version = $versions[$column];if (filter_var($ip, FILTER_VALIDATE_IP, $version === 4 ? FILTER_FLAG_IPV4 : FILTER_FLAG_IPV6) !== false) {$detected[$column] = $ip;}diff --git a/tests/Feature/GetPublicIpsTest.php b/tests/Feature/GetPublicIpsTest.phpindex 477a9d3ed0..24396aeb38 100644--- a/tests/Feature/GetPublicIpsTest.php+++ b/tests/Feature/GetPublicIpsTest.php@@ -8,8 +8,8 @@ uses(RefreshDatabase::class);beforeEach(function () {Process::fake([- 'curl -4s https://ifconfig.io' => "203.0.113.1\n",- 'curl -6s https://ifconfig.io' => "2001:db8::1\n",+ 'curl -4s --max-time 10 https://ifconfig.io' => "203.0.113.1\n",+ 'curl -6s --max-time 10 https://ifconfig.io' => "2001:db8::1\n",]);});@@ -42,13 +42,13 @@ it('detects only the address family that is empty', function () {$settings = InstanceSettings::find(0);expect($settings->public_ipv4)->toBe('203.0.113.21')->and($settings->public_ipv6)->toBe('2001:db8::1');- Process::assertNotRan('curl -4s https://ifconfig.io');+ Process::assertNotRan('curl -4s --max-time 10 https://ifconfig.io');});it('still detects IPv6 when the IPv4 lookup returns an invalid address', function () {Process::fake([- 'curl -4s https://ifconfig.io' => 'not-an-ip',- 'curl -6s https://ifconfig.io' => "2001:db8::1\n",+ 'curl -4s --max-time 10 https://ifconfig.io' => 'not-an-ip',+ 'curl -6s --max-time 10 https://ifconfig.io' => "2001:db8::1\n",]);InstanceSettings::forceCreate(['id' => 0]);@@ -58,3 +58,20 @@ it('still detects IPv6 when the IPv4 lookup returns an invalid address', functioexpect($settings->public_ipv4)->toBeNull()->and($settings->public_ipv6)->toBe('2001:db8::1');});++it('keeps the detected address of one family when the lookup of the other family times out', function (string $failedCommand, string $detectedColumn, string $detectedIp, string $failedColumn) {+ Process::fake([+ $failedCommand => Process::result(exitCode: 28),+ '*' => "{$detectedIp}\n",+ ]);+ InstanceSettings::forceCreate(['id' => 0]);++ get_public_ips();++ $settings = InstanceSettings::find(0);+ expect($settings->$detectedColumn)->toBe($detectedIp)+ ->and($settings->$failedColumn)->toBeNull();+})->with([+ 'IPv6 times out' => ['curl -6s --max-time 10 https://ifconfig.io', 'public_ipv4', '203.0.113.1', 'public_ipv6'],+ 'IPv4 times out' => ['curl -4s --max-time 10 https://ifconfig.io', 'public_ipv6', '2001:db8::1', 'public_ipv4'],+]);diff --git a/tests/Feature/SettingsDetectPublicIpsTest.php b/tests/Feature/SettingsDetectPublicIpsTest.phpindex f2de861987..c4bba54b1b 100644--- a/tests/Feature/SettingsDetectPublicIpsTest.php+++ b/tests/Feature/SettingsDetectPublicIpsTest.php@@ -25,8 +25,8 @@ beforeEach(function () {session(['currentTeam' => $this->rootTeam]);Process::fake([- 'curl -4s https://ifconfig.io' => "203.0.113.1\n",- 'curl -6s https://ifconfig.io' => "2001:db8::1\n",+ 'curl -4s --max-time 10 https://ifconfig.io' => "203.0.113.1\n",+ 'curl -6s --max-time 10 https://ifconfig.io' => "2001:db8::1\n",]);});@@ -44,8 +44,8 @@ it('saves the detected public IPs and shows them in the fields', function () {it('keeps the current value of an address family that cannot be detected', function () {Process::fake([- 'curl -4s https://ifconfig.io' => "203.0.113.1\n",- 'curl -6s https://ifconfig.io' => '',+ 'curl -4s --max-time 10 https://ifconfig.io' => "203.0.113.1\n",+ 'curl -6s --max-time 10 https://ifconfig.io' => '',]);Livewire::test(SettingsIndex::class)@@ -58,8 +58,8 @@ it('keeps the current value of an address family that cannot be detected', functit('shows an error when no address can be detected', function () {Process::fake([- 'curl -4s https://ifconfig.io' => '',- 'curl -6s https://ifconfig.io' => '',+ 'curl -4s --max-time 10 https://ifconfig.io' => '',+ 'curl -6s --max-time 10 https://ifconfig.io' => '',]);Livewire::test(SettingsIndex::class)