Browse Source

control/controlclient: fix deadlock in shutdown

Fixes a deadlock observed in a different repo.
Regressed in 5b3f5eabb5c777910667a6d8297332d223a4af8c.

Updates tailscale/corp#14950
Updates tailscale/corp#14515
Updates tailscale/corp#14139
Updates tailscale/corp#13175

Signed-off-by: Maisem Ali <[email protected]>
Maisem Ali 2 years ago
parent
commit
3655fb3ba0
1 changed files with 3 additions and 2 deletions
  1. 3 2
      control/controlclient/noise.go

+ 3 - 2
control/controlclient/noise.go

@@ -473,11 +473,12 @@ func (nc *NoiseClient) dial(ctx context.Context) (*noiseConn, error) {
 	ncc.h2cc = h2cc
 
 	nc.mu.Lock()
-	defer nc.mu.Unlock()
 	if nc.closed {
-		ncc.Close()
+		nc.mu.Unlock()
+		ncc.Close() // Needs to be called without holding the lock.
 		return nil, errors.New("noise client closed")
 	}
+	defer nc.mu.Unlock()
 	mak.Set(&nc.connPool, ncc.id, ncc)
 	nc.last = ncc
 	return ncc, nil