Skip to content

Commit

Permalink
lxd/migrate: Time out when waiting for connections
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
  • Loading branch information
tomponline committed Oct 26, 2021
1 parent 87f6103 commit 04638c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
18 changes: 16 additions & 2 deletions lxd/migrate_instance.go
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/golang/protobuf/proto"
"github.com/gorilla/websocket"
Expand Down Expand Up @@ -340,7 +341,14 @@ func (s *migrationSourceWs) preDumpLoop(state *state.State, args *preDumpLoopArg
}

func (s *migrationSourceWs) Do(state *state.State, migrateOp *operations.Operation) error {
<-s.allConnected
logger.Info("Waiting for migration channel connections")
select {
case <-time.After(time.Second * 10):
return fmt.Errorf("Timed out waiting for connections")
case <-s.allConnected:
}

logger.Info("Migration channels connected")

var poolMigrationTypes []migration.Type

Expand Down Expand Up @@ -779,7 +787,13 @@ func (c *migrationSink) Do(state *state.State, revert *revert.Reverter, migrateO
var err error

if c.push {
<-c.allConnected
logger.Info("Waiting for migration channel connections")
select {
case <-time.After(time.Second * 10):
return fmt.Errorf("Timed out waiting for connections")
case <-c.allConnected:
}
logger.Info("Migration channels connected")
}

disconnector := c.src.disconnect
Expand Down
19 changes: 17 additions & 2 deletions lxd/migrate_storage_volumes.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

"github.com/golang/protobuf/proto"
"github.com/gorilla/websocket"
Expand Down Expand Up @@ -37,7 +38,15 @@ func newStorageMigrationSource(volumeOnly bool) (*migrationSourceWs, error) {
}

func (s *migrationSourceWs) DoStorage(state *state.State, projectName string, poolName string, volName string, migrateOp *operations.Operation) error {
<-s.allConnected
logger.Info("Waiting for migration channel connections")
select {
case <-time.After(time.Second * 10):
return fmt.Errorf("Timed out waiting for connections")
case <-s.allConnected:
}

logger.Info("Migration channels connected")

defer s.disconnect()

var poolMigrationTypes []migration.Type
Expand Down Expand Up @@ -206,7 +215,13 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
var err error

if c.push {
<-c.allConnected
logger.Info("Waiting for migration channel connections")
select {
case <-time.After(time.Second * 10):
return fmt.Errorf("Timed out waiting for connections")
case <-c.allConnected:
}
logger.Info("Migration channels connected")
}

disconnector := c.src.disconnect
Expand Down

0 comments on commit 04638c5

Please sign in to comment.