From 156fd65078a79ec5bce382505b5ceef6a1495423 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Fri, 13 Jan 2023 11:13:23 -0800 Subject: [PATCH] Propagate sshforward send side connection close 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 --- session/sshforward/copy.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/session/sshforward/copy.go b/session/sshforward/copy.go index 936e1826af92e..d7ecfc3789479 100644 --- a/session/sshforward/copy.go +++ b/session/sshforward/copy.go @@ -3,6 +3,7 @@ package sshforward import ( "context" "io" + "net" "github.com/pkg/errors" "golang.org/x/sync/errgroup" @@ -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()