From 4ae2cd5e0ca44e456c0461172cdef5152b5a74ac Mon Sep 17 00:00:00 2001 From: Jasmine Dahilig Date: Wed, 18 Sep 2019 11:59:32 -0700 Subject: [PATCH] force timeout when boltdb stalls on accessing a data dir that is already in use --- client/state/state_database.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/state/state_database.go b/client/state/state_database.go index bb42a59ae0a..663b09f0bf3 100644 --- a/client/state/state_database.go +++ b/client/state/state_database.go @@ -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" @@ -120,8 +122,11 @@ 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) + db, err := boltdd.Open(fn, 0600, timeout) if err != nil { return nil, fmt.Errorf("failed to create state database: %v", err) }