mirror of
https://github.com/safing/portbase
synced 2025-09-04 19:50:18 +00:00
Merge pull request #107 from safing/fix/retry-bbolt-opening
Add timeout and retrying to opening bbolt dbs
This commit is contained in:
commit
81a4f109e4
1 changed files with 11 additions and 1 deletions
|
@ -32,8 +32,18 @@ func init() {
|
|||
|
||||
// NewBBolt opens/creates a bbolt database.
|
||||
func NewBBolt(name, location string) (storage.Interface, error) {
|
||||
// Create options for bbolt database.
|
||||
dbFile := filepath.Join(location, "db.bbolt")
|
||||
dbOptions := &bbolt.Options{
|
||||
Timeout: 1 * time.Second,
|
||||
}
|
||||
|
||||
db, err := bbolt.Open(filepath.Join(location, "db.bbolt"), 0600, nil)
|
||||
// Open/Create database, retry if there is a timeout.
|
||||
db, err := bbolt.Open(dbFile, 0600, dbOptions)
|
||||
for i := 0; i < 5 && err != nil; i++ {
|
||||
// Try again if there is an error.
|
||||
db, err = bbolt.Open(dbFile, 0600, dbOptions)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue