copy client pointer for keep-alive loop
If a connection fails and attempts to reconnect after the keep-alive loop started, the client will be pulled out from under the keep-alive requests. Close over a local copy of the client, so that reconnecting doesn't race with the keepalive loop terminating.
This commit is contained in:
parent
e6795556f3
commit
bbde7e3e35
|
@ -235,6 +235,10 @@ func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
|
||||||
// Start a keepalive goroutine to help maintain the connection for
|
// Start a keepalive goroutine to help maintain the connection for
|
||||||
// long-running commands.
|
// long-running commands.
|
||||||
log.Printf("[DEBUG] starting ssh KeepAlives")
|
log.Printf("[DEBUG] starting ssh KeepAlives")
|
||||||
|
|
||||||
|
// We wont a local copy of the ssh client pointer, so that a reconnect
|
||||||
|
// doesn't race with the running keep-alive loop.
|
||||||
|
sshClient := c.client
|
||||||
go func() {
|
go func() {
|
||||||
defer cancelKeepAlive()
|
defer cancelKeepAlive()
|
||||||
// Along with the KeepAlives generating packets to keep the tcp
|
// Along with the KeepAlives generating packets to keep the tcp
|
||||||
|
@ -249,7 +253,7 @@ func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
_, _, err := c.client.SendRequest("keepalive@terraform.io", true, nil)
|
_, _, err := sshClient.SendRequest("keepalive@terraform.io", true, nil)
|
||||||
respCh <- err
|
respCh <- err
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue