Skip to content

Commit 64ae32e

Browse files
committed
Close session on io.Copy error in interactive shells
1 parent 2431511 commit 64ae32e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

ssh_session_unix.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ func createPty(s ssh.Session, shell string) {
4747
}
4848
}()
4949

50-
go io.Copy(f, s)
51-
go io.Copy(s, f)
50+
go func() {
51+
io.Copy(f, s)
52+
s.Close()
53+
}()
54+
go func() {
55+
io.Copy(s, f)
56+
s.Close()
57+
}()
5258

5359
done := make(chan error, 1)
5460
go func() { done <- cmd.Wait() }()

ssh_session_windows.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ func createPty(s ssh.Session, shell string) {
127127
defer process.Kill()
128128

129129
// Link data streams of ssh session and conpty
130-
go io.Copy(s, cpty.OutPipe())
131-
go io.Copy(cpty.InPipe(), s)
130+
go func() {
131+
io.Copy(s, cpty.OutPipe())
132+
s.Close()
133+
}()
134+
go func() {
135+
io.Copy(cpty.InPipe(), s)
136+
s.Close()
137+
}()
132138

133139
done := make(chan struct {
134140
*os.ProcessState

0 commit comments

Comments
 (0)