8000 fix: cap max X11 forwarding ports and evict old by spikecurtis · Pull Request #18561 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: cap max X11 forwarding ports and evict old #18561

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 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 16 additions & 4 deletions agent/agentssh/agentssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ type Server struct {
// a lock on mu but protected by closing.
wg sync.WaitGroup

Execer agentexec.Execer
logger slog.Logger
srv *ssh.Server
Execer agentexec.Execer
logger slog.Logger
srv *ssh.Server
x11Forwarder *x11Forwarder

config *Config

Expand Down Expand Up @@ -188,6 +189,14 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
config: config,

metrics: metrics,
x11Forwarder: &x11Forwarder{
logger: logger,
x11HandlerErrors: metrics.x11HandlerErrors,
fs: fs,
displayOffset: *config.X11DisplayOffset,
sessions: make(map[*x11Session]struct{}),
connections: make(map[net.Conn]struct{}),
},
}

srv := &ssh.Server{
Expand Down Expand Up @@ -455,7 +464,7 @@ func (s *Server) sessionHandler(session ssh.Session) {

x11, hasX11 := session.X11()
if hasX11 {
display, handled := s.x11Handler(ctx, x11)
display, handled := s.x11Forwarder.x11Handler(ctx, session)
if !handled {
logger.Error(ctx, "x11 handler failed")
closeCause("x11 handler failed")
Expand Down Expand Up @@ -1114,6 +1123,9 @@ func (s *Server) Close() error {

s.mu.Unlock()

s.logger.Debug(ctx, "closing X11 forwarding")
_ = s.x11Forwarder.Close()

s.logger.Debug(ctx, "waiting for all goroutines to exit")
s.wg.Wait() // Wait for all goroutines to exit.

Expand Down
Loading
Loading
0