Skip to content

Commit

Permalink
Propagate sshforward send side connection close
Browse files Browse the repository at this point in the history
PR #3431 caused connections closed on the remote side of a sshforward
session to not always result in the local side reading an EOF from the
connection. This change restores that behavior by closing the write side
of the forwarded connection after reading an EOF from the stream. Since
only the write side is being closed, it doesn't prevent the remote side
from continuing to read from the connection.

Signed-off-by: Aaron Lehmann <[email protected]>
  • Loading branch information
aaronlehmann committed Jan 13, 2023
1 parent 7bd7285 commit 156fd65
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion session/sshforward/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sshforward
import (
"context"
"io"
"net"

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
Expand All @@ -23,7 +24,10 @@ func Copy(ctx context.Context, conn io.ReadWriteCloser, stream Stream, closeStre
if err := stream.RecvMsg(p); err != nil {
if err == io.EOF {
// indicates client performed CloseSend, but they may still be
// reading data, so don't close conn yet
// reading data
if unixConn, ok := conn.(*net.UnixConn); ok {
unixConn.CloseWrite()
}
return nil
}
conn.Close()
Expand Down

0 comments on commit 156fd65

Please sign in to comment.