diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-10-20 22:15:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-20 22:15:52 -0700 |
| commit | 34054ed91031479a61f8f83795413ef45566d1b3 (patch) | |
| tree | dc35e39e313c944167ee6dbb2c091b951fb77c2e | |
| parent | 82fbf15b711f101bff00e0776c9352c26502cbb2 (diff) | |
| download | seaweedfs-34054ed91031479a61f8f83795413ef45566d1b3.tar.xz seaweedfs-34054ed91031479a61f8f83795413ef45566d1b3.zip | |
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
| -rw-r--r-- | weed/worker/client.go | 5 |
1 files 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() |
