Add 5 seconds timeout for bolt

This commit is contained in:
Jiajie Chen 2020-08-03 14:46:45 +08:00
parent 16b4df1ec2
commit 16e458f354

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
} }