feat(be): timeout of boltdb

This commit is contained in:
Denis Gukov 2021-09-17 15:05:04 +05:00
parent f207aa6bff
commit 6bd6c338f7
2 changed files with 12 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/gorilla/context"
"github.com/gorilla/handlers"
"github.com/spf13/cobra"
"go.etcd.io/bbolt"
"net/http"
"os"
)
@ -110,7 +111,12 @@ func createStore() db.Store {
store := factory.CreateStore()
if err := store.Connect(); err != nil {
fmt.Println("\n Have you run `semaphore setup`?")
switch err {
case bbolt.ErrTimeout:
fmt.Println("\n [ERR_BOLTDB_TIMEOUT] BoltDB supports only one connection at a time. You should stop service when using CLI.")
default:
fmt.Println("\n Have you run `semaphore setup`?")
}
panic(err)
}

View File

@ -9,6 +9,7 @@ import (
"go.etcd.io/bbolt"
"reflect"
"sort"
"time"
)
const MaxID = 2147483647
@ -79,7 +80,10 @@ func (d *BoltDb) Connect() error {
}
var err error
d.db, err = bbolt.Open(filename, 0666, nil)
d.db, err = bbolt.Open(filename, 0666, &bbolt.Options{
Timeout: 5 * time.Second,
})
if err != nil {
return err
}