From 88a1bc31706e32a189704387e3aecf35187b47c4 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Wed, 15 Jan 2025 21:49:31 +0800 Subject: [PATCH] server/proxy/tcpproxy: reuse addr in TCPProxy.Run "addr" is the result of net.JoinHostPort which supports IPv6 address. Rather than ranging "tp.Endpoints" again, it's better to reuse "addr" in the first loop to collect "eps". See #7942 and #7943 for context. Signed-off-by: Jes Cok --- server/proxy/tcpproxy/userspace.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/proxy/tcpproxy/userspace.go b/server/proxy/tcpproxy/userspace.go index c579584b613..cd3a29f340b 100644 --- a/server/proxy/tcpproxy/userspace.go +++ b/server/proxy/tcpproxy/userspace.go @@ -74,14 +74,12 @@ func (tp *TCPProxy) Run() error { if tp.MonitorInterval == 0 { tp.MonitorInterval = 5 * time.Minute } + + var eps []string // for logging for _, srv := range tp.Endpoints { addr := net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port)) tp.remotes = append(tp.remotes, &remote{srv: srv, addr: addr}) - } - - var eps []string - for _, ep := range tp.Endpoints { - eps = append(eps, fmt.Sprintf("%s:%d", ep.Target, ep.Port)) + eps = append(eps, addr) } if tp.Logger != nil { tp.Logger.Info("ready to proxy client requests", zap.Strings("endpoints", eps))