Browse Source

Fix deadlock in worker client Connect() method (#7350)

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/7312/merge
Chris Lu 1 day ago
committed by GitHub
parent
commit
34054ed910
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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