ssh package handles closing the underlying tcp socket

This commit is contained in:
Nate Brown
2026-03-18 18:42:39 -05:00
parent 0c5f48d695
commit 5fc3596b7d

View File

@@ -181,11 +181,7 @@ func (s *SSHServer) run() {
if err != nil { if err != nil {
l := s.l.WithError(err).WithField("remoteAddress", c.RemoteAddr()) l := s.l.WithError(err).WithField("remoteAddress", c.RemoteAddr())
if conn == nil { if conn != nil {
// conn is nil when the handshake failed before authentication
// close the raw TCP connection to avoid leaking the file descriptor.
c.Close()
} else {
l = l.WithField("sshUser", conn.User()) l = l.WithField("sshUser", conn.User())
conn.Close() conn.Close()
} }