From ccc65daebda19d2320abceb4b5495195e6f57980 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Sun, 19 May 2024 01:23:50 +0200 Subject: [PATCH] Close idle conns when closing consul topo Signed-off-by: Tim Vaillancourt --- go/vt/topo/consultopo/server.go | 8 ++++++-- go/vt/vttest/topoctl.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/go/vt/topo/consultopo/server.go b/go/vt/topo/consultopo/server.go index a7a5446c274..049af5bf869 100644 --- a/go/vt/topo/consultopo/server.go +++ b/go/vt/topo/consultopo/server.go @@ -165,9 +165,13 @@ func parseConsulLockSessionChecks(s string) []string { } // Close implements topo.Server.Close. -// It will nil out the global and cells fields, so any attempt to -// re-use this server will panic. +// It will close idle http connections and nil out the global +// and cells fields, so any attempt to re-use this server +// will panic. func (s *Server) Close() { + if consulConfig.Transport != nil { + consulConfig.Transport.CloseIdleConnections() + } s.client = nil s.kv = nil s.mu.Lock() diff --git a/go/vt/vttest/topoctl.go b/go/vt/vttest/topoctl.go index 2b63900d6d8..1fd4cb6e101 100644 --- a/go/vt/vttest/topoctl.go +++ b/go/vt/vttest/topoctl.go @@ -31,6 +31,7 @@ func (ctl *Topoctl) Setup() error { if err != nil { return err } + defer topoServer.Close() log.Infof("Creating cells if they don't exist in the provided topo server %s %s %s", ctl.TopoImplementation, ctl.TopoGlobalServerAddress, ctl.TopoGlobalRoot) // Create cells if it doesn't exist to be idempotent. Should work when we share the same topo server across multiple local clusters.