Skip to content

Commit

Permalink
server/proxy/tcpproxy: reuse addr in TCPProxy.Run
Browse files Browse the repository at this point in the history
"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 <[email protected]>
  • Loading branch information
callthingsoff committed Jan 15, 2025
1 parent ce4b4e5 commit 88a1bc3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions server/proxy/tcpproxy/userspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 88a1bc3

Please sign in to comment.