Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(agent): add connection reporting for SSH and reconnecing PTY #16652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
net.SplitHostPort
  • Loading branch information
mafredri committed Feb 24, 2025
commit 82b6fab00bb8c09d6675fc01612358d3e1f7c02d
11 changes: 7 additions & 4 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"net/netip"
"os"
Expand Down Expand Up @@ -779,10 +780,12 @@ func (a *agent) reportConnection(id uuid.UUID, connectionType proto.Connection_T
return func(int, string) {} // Noop.
}

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

a.reportConnectionsMu.Lock()
Expand Down
Loading