Skip to content

Commit

Permalink
extend timeout for restores
Browse files Browse the repository at this point in the history
  • Loading branch information
gulducat committed Dec 2, 2024
1 parent 6703174 commit 436fd23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulProxie
c.pluginManagers.RegisterAndRun(devManager)

c.hostVolumeManager, err = hvm.NewHostVolumeManager(logger,
c.stateDB,
c.stateDB, hostVolumeRequestTimeout,
cfg.HostVolumePluginDir,
cfg.AllocMountsDir)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions client/hostvolumemanager/host_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type HostVolumeManager struct {
}

func NewHostVolumeManager(logger hclog.Logger,
stateMgr HostVolumeStateManager,
stateMgr HostVolumeStateManager, restoreTimeout time.Duration,
pluginDir, sharedMountDir string) (*HostVolumeManager, error) {

log := logger.Named("host_volume_mgr")
Expand All @@ -41,14 +41,14 @@ func NewHostVolumeManager(logger hclog.Logger,
log: log,
}

if err := hvm.restoreState(stateMgr); err != nil {
if err := hvm.restoreState(stateMgr, restoreTimeout); err != nil {
return nil, err
}

return hvm, nil
}

func (hvm *HostVolumeManager) restoreState(state HostVolumeStateManager) error {
func (hvm *HostVolumeManager) restoreState(state HostVolumeStateManager, timeout time.Duration) error {
vols, err := state.GetDynamicHostVolumes()
if err != nil {
return err
Expand All @@ -64,7 +64,7 @@ func (hvm *HostVolumeManager) restoreState(state HostVolumeStateManager) error {
wg.Add(1)
func() {
defer wg.Done()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// note: this will rewrite client state that we just restored
if _, err := hvm.Create(ctx, vol.CreateReq); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions client/hostvolumemanager/host_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"sync"
"testing"
"time"

cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/helper/testlog"
Expand All @@ -33,7 +34,7 @@ func TestNewHostVolumeManager_restoreState(t *testing.T) {
// resulting in a volume directory in this mountDir.
mountDir := t.TempDir()

_, err := NewHostVolumeManager(log, state, "/wherever", mountDir)
_, err := NewHostVolumeManager(log, state, time.Second, "/wherever", mountDir)
must.NoError(t, err)

volPath := filepath.Join(mountDir, vol.ID)
Expand All @@ -43,7 +44,7 @@ func TestNewHostVolumeManager_restoreState(t *testing.T) {
t.Run("get error", func(t *testing.T) {
state := newMockState()
state.getErr = errors.New("get error")
_, err := NewHostVolumeManager(log, state, "/wherever", "/wherever")
_, err := NewHostVolumeManager(log, state, time.Second, "/wherever", "/wherever")
// error loading state should break the world
must.ErrorIs(t, err, state.getErr)
})
Expand All @@ -58,7 +59,7 @@ func TestNewHostVolumeManager_restoreState(t *testing.T) {
must.Error(t, state.PutDynamicHostVolume(vol))

// restore process also attempts a state Put during vol Create
_, err := NewHostVolumeManager(log, state, "/wherever", t.TempDir())
_, err := NewHostVolumeManager(log, state, time.Second, "/wherever", t.TempDir())
// but it should not cause the whole agent to fail to start
must.NoError(t, err)
})
Expand Down

0 comments on commit 436fd23

Please sign in to comment.