From a0091642be6edae5d5f85d6300778be7ca9e01e1 Mon Sep 17 00:00:00 2001 From: Bin Shi Date: Thu, 1 Jun 2023 02:00:21 -0700 Subject: [PATCH] Delete the tso ms discovery when switching away from API mode. Signed-off-by: Bin Shi --- client/client.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/client.go b/client/client.go index 631dfb39b0d..c2f673c5da0 100644 --- a/client/client.go +++ b/client/client.go @@ -621,13 +621,13 @@ func (c *client) setServiceMode(newMode pdpb.ServiceMode) { oldTSOClient.Close() // Replace the old TSO service discovery if needed. oldTSOSvcDiscovery := c.tsoSvcDiscovery - if newTSOSvcDiscovery != nil { - c.tsoSvcDiscovery = newTSOSvcDiscovery - // Close the old TSO service discovery safely after both the old client - // and service discovery are replaced. - if oldTSOSvcDiscovery != nil { - oldTSOSvcDiscovery.Close() - } + // If newTSOSvcDiscovery is nil, that's expected, as it means we are switching to PD service mode and + // no tso microservice discovery is needed. + c.tsoSvcDiscovery = newTSOSvcDiscovery + // Close the old TSO service discovery safely after both the old client and service discovery are replaced. + if oldTSOSvcDiscovery != nil { + // We are switching from API service mode to PD service mode, so delete the old tso microservice discovery. + oldTSOSvcDiscovery.Close() } oldMode := c.serviceMode c.serviceMode = newMode