From 575aacb1e2a907f9eed9bc2f9eac14460176b47d Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Sat, 28 May 2022 04:36:30 -0700 Subject: [PATCH] ssh/tailssh: terminate sessions on stdout copy failures Currently, killing a SCP copy with a Ctrl+C leaves the session hanging even though the stdout copy goroutine fails with an io.EOF. Taking a step back, when we are unable to send any more data back to the client we should just terminate the session as the client will stop getting any response from the server anyways. Updates #3802 Signed-off-by: Maisem Ali --- ssh/tailssh/tailssh.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ssh/tailssh/tailssh.go b/ssh/tailssh/tailssh.go index 43be7498a..97d36e55d 100644 --- a/ssh/tailssh/tailssh.go +++ b/ssh/tailssh/tailssh.go @@ -946,15 +946,17 @@ func (ss *sshSession) run() { _, err := io.Copy(rec.writer("i", ss.stdin), ss) if err != nil { // TODO: don't log in the success case. - logf("ssh: stdin copy: %v", err) + logf("stdin copy: %v", err) } ss.stdin.Close() }() go func() { _, err := io.Copy(rec.writer("o", ss), ss.stdout) if err != nil { - // TODO: don't log in the success case. - logf("ssh: stdout copy: %v", err) + logf("stdout copy: %v", err) + // If we got an error here, it's probably because the client has + // disconnected. + ss.ctx.CloseWithError(err) } }() // stderr is nil for ptys. @@ -962,8 +964,7 @@ func (ss *sshSession) run() { go func() { _, err := io.Copy(ss.Stderr(), ss.stderr) if err != nil { - // TODO: don't log in the success case. - logf("ssh: stderr copy: %v", err) + logf("stderr copy: %v", err) } }() }