control/controlclient: fix deadlock in shutdown

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

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

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali 2023-10-03 17:57:02 -07:00 committed by Maisem Ali
parent 5902d51ba4
commit 3655fb3ba0

View File

@ -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