diff --git a/client/alloc_runner.go b/client/alloc_runner.go index e2705a341..d79374ef1 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -180,12 +180,9 @@ func (r *AllocRunner) SaveState() error { func (r *AllocRunner) saveAllocRunnerState() error { // Create the snapshot. - r.taskStatusLock.RLock() - states := copyTaskStates(r.taskStates) - r.taskStatusLock.RUnlock() - alloc := r.Alloc() r.allocLock.Lock() + states := alloc.TaskStates allocClientStatus := r.allocClientStatus allocClientDescription := r.allocClientDescription r.allocLock.Unlock() diff --git a/client/util.go b/client/util.go index 369b5f059..ff2fa3d25 100644 --- a/client/util.go +++ b/client/util.go @@ -92,6 +92,13 @@ func persistState(path string, data interface{}) error { if err := os.Rename(tmpPath, path); err != nil { return fmt.Errorf("failed to rename tmp to path: %v", err) } + + // Sanity check since users have reported empty state files on disk + if stat, err := os.Stat(path); err != nil { + return fmt.Errorf("unable to stat state file %s: %v", path, err) + } else if stat.Size() == 0 { + return fmt.Errorf("persisted invalid state file %s; see https://github.com/hashicorp/nomad/issues/1367") + } return nil }