From 1a98d7deb803e79446b74863b1170b7032345b19 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 20 Oct 2025 21:07:32 -0700 Subject: [PATCH] Fix deadlock in worker client Connect() method The Connect() method was holding a write lock via defer for its entire duration, including when calling attemptConnection(). This caused a deadlock because attemptConnection() tries to acquire a read lock at line 119 to access c.lastWorkerInfo. The fix removes the defer unlock pattern and manually releases the lock after checking the connected state but before calling attemptConnection(). This allows attemptConnection() to acquire its own locks without deadlock. Fixes #7192 --- weed/worker/client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weed/worker/client.go b/weed/worker/client.go index a90eac643..9066afdf3 100644 --- a/weed/worker/client.go +++ b/weed/worker/client.go @@ -74,11 +74,12 @@ func NewGrpcAdminClient(adminAddress string, workerID string, dialOption grpc.Di // Connect establishes gRPC connection to admin server with TLS detection func (c *GrpcAdminClient) Connect() error { c.mutex.Lock() - defer c.mutex.Unlock() - if c.connected { + c.mutex.Unlock() return fmt.Errorf("already connected") } + // Release lock before calling attemptConnection which needs to acquire locks internally + c.mutex.Unlock() // Always start the reconnection loop, even if initial connection fails go c.reconnectionLoop()