From 1b757786584d2bdb7af34addd29874e77c900b22 Mon Sep 17 00:00:00 2001 From: Vishnuvardhan Reddy Date: Tue, 24 Feb 2026 18:31:59 +0000 Subject: [PATCH] fix: resolve deadlock in Restart method The Restart() method was acquiring a lock then calling Stop() which tried to acquire the same lock, causing a deadlock. Fixed by creating stopLocked() method that assumes lock is already held, and having Restart() call stopLocked() directly. --- pkg/daemon/service.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/daemon/service.go b/pkg/daemon/service.go index b91cbb39c..0824777c3 100644 --- a/pkg/daemon/service.go +++ b/pkg/daemon/service.go @@ -190,7 +190,12 @@ func (s *Service) Start() error { func (s *Service) Stop() error { s.mu.Lock() defer s.mu.Unlock() + return s.stopLocked() +} +// stopLocked stops the running gateway daemon without acquiring the lock. +// Must be called with the lock already held. +func (s *Service) stopLocked() error { logger.InfoC("daemon", "Stopping gateway daemon") pid := s.pidFile.Read() @@ -254,9 +259,9 @@ func (s *Service) Restart() error { logger.InfoC("daemon", "Restarting gateway daemon") - // Stop if running + // Stop if running (call stopLocked to avoid deadlock) if s.pidFile.IsProcessRunning() { - if err := s.Stop(); err != nil { + if err := s.stopLocked(); err != nil { return fmt.Errorf("failed to stop daemon: %w", err) } }