From 2fc870c6eb0818969fd6ce63bc8b357501199c60 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 4 Dec 2025 08:57:03 +0100 Subject: [PATCH] Fix ineffective restartInitiated guard with proper debouncing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guard was setting and immediately resetting the flag in the same synchronous execution, providing no actual protection. Now the flag stays true until proxy reaches a stable state (running/exited/error) via WebSocket notification, with additional client-side guard. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/Livewire/Server/Navbar.php | 11 ++++++----- resources/views/livewire/server/navbar.blade.php | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Livewire/Server/Navbar.php b/app/Livewire/Server/Navbar.php index 6da1edd77..cd9cfcba6 100644 --- a/app/Livewire/Server/Navbar.php +++ b/app/Livewire/Server/Navbar.php @@ -67,7 +67,7 @@ public function restart() try { $this->authorize('manageProxy', $this->server); - // Prevent duplicate restart messages (e.g., from double-click or re-render) + // Prevent duplicate restart calls if ($this->restartInitiated) { return; } @@ -75,10 +75,6 @@ public function restart() // Always use background job for all servers RestartProxyJob::dispatch($this->server); - // $this->dispatch('info', 'Proxy restart initiated.'); - - // Reset the flag after a short delay to allow future restarts - $this->restartInitiated = false; } catch (\Throwable $e) { $this->restartInitiated = false; @@ -147,6 +143,11 @@ public function showNotification($event = null) $this->dispatch('activityMonitor', $event['activityId']); } + // Reset restart flag when proxy reaches a stable state + if (in_array($this->proxyStatus, ['running', 'exited', 'error'])) { + $this->restartInitiated = false; + } + // Skip notification if we already notified about this status (prevents duplicates) if ($this->lastNotifiedStatus === $this->proxyStatus) { return; diff --git a/resources/views/livewire/server/navbar.blade.php b/resources/views/livewire/server/navbar.blade.php index b0802ed1e..4f43ef7e2 100644 --- a/resources/views/livewire/server/navbar.blade.php +++ b/resources/views/livewire/server/navbar.blade.php @@ -181,6 +181,7 @@ class="flex items-center gap-6 overflow-x-scroll sm:overflow-x-hidden scrollbar } }); $wire.$on('restartEvent', () => { + if ($wire.restartInitiated) return; window.dispatchEvent(new CustomEvent('startproxy')) $wire.$call('restart'); });