Skip to content
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

[v13] Fix leaking connection monitor instances. Expand comment with a warning. #31042

Merged
merged 2 commits into from Aug 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/srv/db/proxyserver.go
Expand Up @@ -507,6 +507,9 @@ func isReverseTunnelDownError(err error) bool {
//
// Implements common.Service.
func (s *ProxyServer) Proxy(ctx context.Context, proxyCtx *common.ProxyContext, clientConn, serviceConn net.Conn) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

// Wrap a client connection with a monitor that auto-terminates
// idle connection and connection with expired cert.
var err error
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/db/server.go
Expand Up @@ -1002,7 +1002,7 @@ func (s *Server) handleConnection(ctx context.Context, clientConn net.Conn) erro

// Wrap a client connection into monitor that auto-terminates
// idle connection and connection with expired cert.
ctx, clientConn, err = s.cfg.ConnectionMonitor.MonitorConn(ctx, sessionCtx.AuthContext, clientConn)
ctx, clientConn, err = s.cfg.ConnectionMonitor.MonitorConn(cancelCtx, sessionCtx.AuthContext, clientConn)
if err != nil {
return trace.Wrap(err)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/srv/monitor.go
Expand Up @@ -213,7 +213,8 @@ type MonitorConfig struct {
Tracker ActivityTracker
// Conn is a connection to close
Conn TrackingConn
// Context is an external context to cancel the operation
// Context is an external context. To reliably close the monitor and ensure no goroutine leak,
// make sure to pass a context which will be canceled on time.
Context context.Context
// Login is linux box login
Login string
Expand Down