Skip to content

Commit

Permalink
[v13] Fix leaking connection monitor instances. Expand comment with a…
Browse files Browse the repository at this point in the history
… warning. (#31042)

* Fix leaking connection monitor instances. Expand comment with a warning.

* Fix typo.
  • Loading branch information
Tener committed Aug 25, 2023
1 parent 3446f63 commit 742f1b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
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

0 comments on commit 742f1b2

Please sign in to comment.