MCPcopy Create free account
hub / github.com/coder/coder / evictLeastRecentlyUsedSession

Method evictLeastRecentlyUsedSession

agent/agentssh/x11.go:294–312  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

292}
293
294func (x *x11Forwarder) evictLeastRecentlyUsedSession() {
295 lru := x.popLeastRecentlyUsedSession()
296 if lru == nil {
297 return
298 }
299 err := lru.listener.Close()
300 if err != nil {
301 x.logger.Error(context.Background(), "failed to close evicted X11 session listener", slog.Error(err))
302 }
303 // when we evict, we also want to force the SSH session to be closed as well. This is because we intend to reuse
304 // the X11 TCP listener port for a new X11 forwarding session. If we left the SSH session up, then graphical apps
305 // started in that session could potentially connect to an unintended X11 Server (i.e. the display on a different
306 // computer than the one that started the SSH session). Most likely, this session is a zombie anyway if we've
307 // reached the maximum number of X11 forwarding sessions.
308 err = lru.session.Close()
309 if err != nil {
310 x.logger.Error(context.Background(), "failed to close evicted X11 SSH session", slog.Error(err))
311 }
312}
313
314// createX11Listener creates a listener for X11 forwarding, it will use
315// the next available port starting from X11StartPort and displayOffset.

Callers 1

createX11SessionMethod · 0.95

Calls 3

CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected