Skip to content

Commit

Permalink
Close ssh tunnel when either end closes the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Qining committed Sep 7, 2018
1 parent 73abbe5 commit dab8fc1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/os/device/remotessh/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,17 @@ func (b binding) doTunnel(ctx context.Context, local net.Conn, remotePort int) e

wg := sync.WaitGroup{}

copy := func(writer io.Writer, reader io.Reader) {
copy := func(writer net.Conn, reader net.Conn) {
_, err := io.Copy(writer, reader)
writer.Close()
// Ignore the 'use of closed network connection' error for 'read' operation
if e, ok := err.(*net.OpError); ok {
if (e.Op == "read") && (e.Err.Error() == "use of closed network connection") {
err = nil
}
}
if err != nil {
log.E(ctx, "Copy Error %s", err)
log.E(ctx, "Copy Error, error type: %T, error msg: %s", err, err)
}
wg.Done()
}
Expand Down

0 comments on commit dab8fc1

Please sign in to comment.