bolt: strict 10 second timeout for opening databases

This commit is contained in:
mappu 2017-05-21 18:05:20 +12:00
parent f0f642b6b0
commit b5149c4efa

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"os"
"time"
"github.com/boltdb/bolt"
)
@ -26,7 +27,9 @@ func GetMagic() int64 {
//export Bolt_Open
func Bolt_Open(path string) (ObjectReference, *C.char, int) {
ptrDB, err := bolt.Open(path, os.FileMode(0644), bolt.DefaultOptions)
opts := *bolt.DefaultOptions
opts.Timeout = 10 * time.Second
ptrDB, err := bolt.Open(path, os.FileMode(0644), &opts)
if err != nil {
errMsg := err.Error()
return 0, C.CString(errMsg), len(errMsg)