Browse Source

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
pull/7350/head
Chris Lu 12 hours ago
parent
commit
1a98d7deb8
  1. 5
      weed/worker/client.go

5
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()

Loading…
Cancel
Save