Skip to content

Commit

Permalink
force timeout when boltdb stalls on accessing a data dir that is alre…
Browse files Browse the repository at this point in the history
…ady in use
  • Loading branch information
jazzyfresh committed Sep 24, 2019
1 parent df03de8 commit 67d1a60
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client/state/state_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path/filepath"
"time"

"github.com/boltdb/bolt"

hclog "github.com/hashicorp/go-hclog"
trstate "github.com/hashicorp/nomad/client/allocrunner/taskrunner/state"
dmstate "github.com/hashicorp/nomad/client/devicemanager/state"
Expand Down Expand Up @@ -120,9 +122,14 @@ func NewBoltStateDB(logger hclog.Logger, stateDir string) (StateDB, error) {
}
firstRun := fi == nil

// Timeout to force failure when accessing a data dir that is already in use
timeout := &bolt.Options{Timeout: 5 * time.Second}

// Create or open the boltdb state database
db, err := boltdd.Open(fn, 0600, nil)
if err != nil {
db, err := boltdd.Open(fn, 0600, timeout)
if err == bolt.ErrTimeout {
return nil, fmt.Errorf("timed out while opening database, is another Nomad process accessing data_dir %s?", stateDir)
} else if err != nil {
return nil, fmt.Errorf("failed to create state database: %v", err)
}

Expand Down

0 comments on commit 67d1a60

Please sign in to comment.