Close SSH connections once we're done with them

Fixes "Waiting for SSH" hang at end of install
This commit is contained in:
Cheng Sun 2014-12-09 17:44:21 +00:00
parent 1450fd0568
commit 97df6fd283

View File

@ -94,14 +94,19 @@ func forward(local_conn net.Conn, config *gossh.ClientConfig, server, remote_des
ssh_conn, err := ssh_client_conn.Dial("tcp", remote_loc)
if err != nil {
log.Printf("ssh.Dial error: %s", err)
ssh_client_conn.Close()
return err
}
txDone := make(chan struct{})
rxDone := make(chan struct{})
go func() {
_, err = io.Copy(ssh_conn, local_conn)
if err != nil {
log.Printf("io.copy failed: %v", err)
}
close(txDone)
}()
go func() {
@ -109,6 +114,14 @@ func forward(local_conn net.Conn, config *gossh.ClientConfig, server, remote_des
if err != nil {
log.Printf("io.copy failed: %v", err)
}
close(rxDone)
}()
go func() {
<-txDone
<-rxDone
ssh_client_conn.Close()
ssh_conn.Close()
}()
return nil