Merge pull request #130 from tuna/add-bolt-open-timeout

Add 5 seconds timeout for bolt
This commit is contained in:
Yuxiang Zhang 2020-08-05 12:41:29 +08:00 committed by GitHub
commit b34238c097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
@ -26,7 +27,9 @@ type dbAdapter interface {
func makeDBAdapter(dbType string, dbFile string) (dbAdapter, error) { func makeDBAdapter(dbType string, dbFile string) (dbAdapter, error) {
if dbType == "bolt" { if dbType == "bolt" {
innerDB, err := bolt.Open(dbFile, 0600, nil) innerDB, err := bolt.Open(dbFile, 0600, &bolt.Options{
Timeout: 5 * time.Second,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }