Skip to content

Commit 252fdcc

Browse files
Fix: ssh connector closes failed connections
1 parent b740617 commit 252fdcc

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

internal/plugin/connectors/ssh/proxy_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (proxy *proxyService) Start() error {
130130
// https://godoc.org/golang.org/x/crypto/ssh#NewServerConn
131131
conn, chans, reqs, err := ssh.NewServerConn(nConn, serverConfig)
132132
if err != nil {
133+
nConn.Close()
133134
logger.Debugf("Failed to handshake: %s", err)
134135
continue
135136
}
@@ -149,6 +150,7 @@ func (proxy *proxyService) Start() error {
149150
go func() {
150151
if err := proxy.handleConnections(chans); err != nil {
151152
logger.Errorf("Failed on handle connection: %s", err)
153+
nConn.Close()
152154
return
153155
}
154156

internal/plugin/connectors/ssh/service_connector.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func (h *ServiceConnector) Connect(
9898
}
9999

100100
if server, err = ssh.Dial(serverConfig.Network, serverConfig.Address, &serverConfig.ClientConfig); err != nil {
101+
for newChannel := range h.channels {
102+
if err := newChannel.Reject(ssh.ConnectionFailed, "secretless unable to dial SSH backend"); err != nil {
103+
h.logger.Errorf("Failed to send new channel rejection on dial SSH backend : %s", err)
104+
}
105+
}
101106
return fmt.Errorf("failed to dial SSH backend '%s': %s", serverConfig.Address, err)
102107
}
103108

0 commit comments

Comments
 (0)