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
This commit is contained in:
Kushagra Sharma 2018-12-17 04:11:11 -05:00 committed by Nishant Das
parent 4f316d6ed0
commit a0c540d780

View File

@ -3,8 +3,9 @@ package db
import ( import (
"os" "os"
"path" "path"
"time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"errors"
) )
// BeaconDB manages the data layer of the beacon chain implementation. // BeaconDB manages the data layer of the beacon chain implementation.
@ -46,8 +47,11 @@ func NewDB(dirPath string) (*BeaconDB, error) {
return nil, err return nil, err
} }
datafile := path.Join(dirPath, "beaconchain.db") 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 != nil {
if err == bolt.ErrTimeout {
return nil, errors.New("cannot obtain database lock, database may be in use by another process")
}
return nil, err return nil, err
} }