From 8c978cf909068e0f1aacd039a8100f0190a426f1 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/session/sshforward/copy.go b/session/sshforward/copy.go index 936e1826af92..a4a065b46e36 100644 --- a/session/sshforward/copy.go +++ b/session/sshforward/copy.go @@ -23,7 +23,12 @@ 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 conn, ok := conn.(interface { + CloseWrite() error + }); ok { + conn.CloseWrite() + } return nil } conn.Close()