Merge pull request #32 from rdobson/port_race
Fixing race condition between port test and attempting to listen.
This commit is contained in:
commit
274d86cdc6
@ -142,7 +142,7 @@ func forward(local_conn net.Conn, config *gossh.ClientConfig, server, remote_des
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ssh_port_forward(local_port uint, remote_port uint, remote_dest, host, username, password string) error {
|
func ssh_port_forward(local_listener net.Listener, remote_port uint, remote_dest, host, username, password string) error {
|
||||||
|
|
||||||
config := &gossh.ClientConfig{
|
config := &gossh.ClientConfig{
|
||||||
User: username,
|
User: username,
|
||||||
@ -151,16 +151,6 @@ func ssh_port_forward(local_port uint, remote_port uint, remote_dest, host, user
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen on a local port
|
|
||||||
local_listener, err := net.Listen("tcp",
|
|
||||||
fmt.Sprintf("%s:%d",
|
|
||||||
"127.0.0.1",
|
|
||||||
local_port))
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Local listen failed: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
local_connection, err := local_listener.Accept()
|
local_connection, err := local_listener.Accept()
|
||||||
|
|
||||||
|
@ -30,14 +30,12 @@ func (self *StepForwardPortOverSSH) Run(state multistep.StateBag) multistep.Step
|
|||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Close()
|
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Creating a local port forward over SSH on local port %d", sshHostPort))
|
ui.Say(fmt.Sprintf("Creating a local port forward over SSH on local port %d", sshHostPort))
|
||||||
|
|
||||||
remotePort, _ := self.RemotePort(state)
|
remotePort, _ := self.RemotePort(state)
|
||||||
remoteDest, _ := self.RemoteDest(state)
|
remoteDest, _ := self.RemoteDest(state)
|
||||||
|
|
||||||
go ssh_port_forward(sshHostPort, remotePort, remoteDest, config.HostIp, config.Username, config.Password)
|
go ssh_port_forward(l, remotePort, remoteDest, config.HostIp, config.Username, config.Password)
|
||||||
ui.Say(fmt.Sprintf("Port forward setup. %d ---> %s:%d on %s", sshHostPort, remoteDest, remotePort, config.HostIp))
|
ui.Say(fmt.Sprintf("Port forward setup. %d ---> %s:%d on %s", sshHostPort, remoteDest, remotePort, config.HostIp))
|
||||||
|
|
||||||
// Provide the local port to future steps.
|
// Provide the local port to future steps.
|
||||||
|
Loading…
Reference in New Issue
Block a user