10000 net.SplitHostPort · coder/coder@82b6fab · GitHub
[go: up one dir, main page]

Skip to content

Commit 82b6fab

Browse files
committed
net.SplitHostPort
1 parent 17ddb8e commit 82b6fab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

agent/agent.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io"
10+
"net"
1011
"net/http"
1112
"net/netip"
1213
"os"
@@ -779,10 +780,12 @@ func (a *agent) reportConnection(id uuid.UUID, connectionType proto.Connection_T
779780
return func(int, string) {} // Noop.
780781
}
781782

782-
// Remove the port from the IP.
783-
if portIndex := strings.LastIndex(ip, ":"); portIndex != -1 {
784-
ip = ip[:portIndex]
785-
ip = strings.Trim(ip, "[]") // IPv6 addresses are wrapped in brackets.
783+
// Remove the port from the IP because ports are not supported in coderd.
784+
if host, _, err := net.SplitHostPort(ip); err != nil {
785+
a.logger.Error(a.hardCtx, "split host and port for connection report failed", slog.F("ip", ip), slog.Error(err))
786+
} else {
787+
// Best effort.
788+
ip = host
786789
}
787790

788791
a.reportConnectionsMu.Lock()

0 commit comments

Comments
 (0)
0