fix: ensure SSH connections close on client disconnect
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 4m20s

This commit is contained in:
2025-07-23 12:40:20 +07:00
parent f6ad5c81e3
commit c4dd086fb3
2 changed files with 36 additions and 8 deletions

View File

@ -11,7 +11,11 @@ func (s *Server) handleConnection(conn net.Conn) {
sshConn, chans, forwardingReqs, err := ssh.NewServerConn(conn, s.Config)
if err != nil {
log.Printf("failed to establish SSH connection: %v", err)
conn.Close()
err := conn.Close()
if err != nil {
log.Printf("failed to close SSH connection: %v", err)
return
}
return
}
@ -21,5 +25,12 @@ func (s *Server) handleConnection(conn net.Conn) {
for ch := range chans {
newSession.ChannelChan <- ch
}
defer func(newSession *session.Session) {
err := newSession.Close()
if err != nil {
log.Printf("failed to close session: %v", err)
}
}(newSession)
return
}