From a0c540d780a5ccf51e89e8b40a6654dbfe363bcc Mon Sep 17 00:00:00 2001 From: Kushagra Sharma Date: Mon, 17 Dec 2018 04:11:11 -0500 Subject: [PATCH] Fixed hang when multiple processes open same DB (#1116) * Fixed hang when multiple processes open same DB * fixed error check and message * removed punctuation on error message --- beacon-chain/db/db.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/beacon-chain/db/db.go b/beacon-chain/db/db.go index db065b1c8..be8c82887 100644 --- a/beacon-chain/db/db.go +++ b/beacon-chain/db/db.go @@ -3,8 +3,9 @@ package db import ( "os" "path" - + "time" "github.com/boltdb/bolt" + "errors" ) // BeaconDB manages the data layer of the beacon chain implementation. @@ -46,8 +47,11 @@ func NewDB(dirPath string) (*BeaconDB, error) { return nil, err } datafile := path.Join(dirPath, "beaconchain.db") - boltDB, err := bolt.Open(datafile, 0600, nil) + boltDB, err := bolt.Open(datafile, 0600, &bolt.Options{Timeout: 1 * time.Second}) if err != nil { + if err == bolt.ErrTimeout { + return nil, errors.New("cannot obtain database lock, database may be in use by another process") + } return nil, err }