From 3655fb3ba05413aeadf82a013d6d17b36998c0d4 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Tue, 3 Oct 2023 17:57:02 -0700 Subject: [PATCH] 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 --- control/controlclient/noise.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/control/controlclient/noise.go b/control/controlclient/noise.go index a5439062f..660760995 100644 --- a/control/controlclient/noise.go +++ b/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