Skip to content

Commit a4987e8

Browse files
easwarsjanardhankrishna-sai
authored andcommitted
xdsclient: release lock before attempting to close underlying transport (grpc#8011)
1 parent ccb6061 commit a4987e8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

xds/internal/xdsclient/client_refcounted.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@ var (
4040

4141
func clientRefCountedClose(name string) {
4242
clientsMu.Lock()
43-
defer clientsMu.Unlock()
44-
4543
client, ok := clients[name]
4644
if !ok {
4745
logger.Errorf("Attempt to close a non-existent xDS client with name %s", name)
46+
clientsMu.Unlock()
4847
return
4948
}
5049
if client.decrRef() != 0 {
50+
clientsMu.Unlock()
5151
return
5252
}
53+
delete(clients, name)
54+
clientsMu.Unlock()
55+
56+
// This attempts to close the transport to the management server and could
57+
// theoretically call back into the xdsclient package again and deadlock.
58+
// Hence, this needs to be called without holding the lock.
5359
client.clientImpl.close()
5460
xdsClientImplCloseHook(name)
55-
delete(clients, name)
5661

5762
}
5863

0 commit comments

Comments
 (0)