Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03db373

Browse files
committed
Close SSH client as well due to use of multiple sessions during forwarding
1 parent 0f3af93 commit 03db373

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cli/ssh.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func (r *RootCmd) ssh() *clibase.Cmd {
114114
if err != nil {
115115
return err
116116
}
117-
watchAndClose := func(c io.Closer) {
117+
watchAndClose := func(closer func() error) {
118118
// Ensure session is ended on both context cancellation
119119
// and workspace stop.
120-
defer c.Close()
120+
defer closer()
121121

122122
for {
123123
select {
@@ -145,7 +145,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
145145
return err
146146
}
147147
defer rawSSH.Close()
148-
go watchAndClose(rawSSH)
148+
go watchAndClose(rawSSH.Close)
149149

150150
go func() {
151151
// Ensure stdout copy closes incase stdin is closed
@@ -170,7 +170,11 @@ func (r *RootCmd) ssh() *clibase.Cmd {
170170
return err
171171
}
172172
defer sshSession.Close()
173-
go watchAndClose(sshSession)
173+
go watchAndClose(func() error {
174+
_ = sshSession.Close()
175+
_ = sshClient.Close()
176+
return nil
177+
})
174178

175179
if identityAgent == "" {
176180
identityAgent = os.Getenv("SSH_AUTH_SOCK")

0 commit comments

Comments
 (0)