Skip to content

Commit

Permalink
Handle remote failure (#19)
Browse files Browse the repository at this point in the history
Similar to changes in #18 - closes open connections immediately on remote dial failure.
  • Loading branch information
hownowstephen committed Oct 16, 2023
1 parent 93cd1e6 commit d87a21f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ssh_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ func (tunnel *SSHTunnel) forward(localConn net.Conn) {
remoteConn, err := serverConn.Dial("tcp", tunnel.Remote.String())
if err != nil {
tunnel.logf("remote dial error: %s", err)

if err := serverConn.Close(); err != nil {
tunnel.logf("failed to close server connection: %v", err)
}
if err := localConn.Close(); err != nil {
tunnel.logf("failed to close local connection: %v", err)
}
return
}
tunnel.Conns = append(tunnel.Conns, remoteConn)
Expand Down

0 comments on commit d87a21f

Please sign in to comment.