Skip to content

Commit

Permalink
storage: Use timeout for boltdb database opening
Browse files Browse the repository at this point in the history
To dump the DB, the service must be stopped.
If this is not the case `dump` command just hangs without any output,
which _may_ be unexpected from the ops POV.
Introduce a 1 second timeous, which is more than enough, given
that bbolt retries doing flock() every 50ms.

Signed-off-by: Evgenii Stratonikov <fyfyrchik@runbox.com>
  • Loading branch information
fyfyrchik committed Oct 6, 2023
1 parent 91c928e commit f1c6b9f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/core/storage/boltdb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"time"

"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
"github.com/nspcc-dev/neo-go/pkg/io"
Expand All @@ -21,6 +22,10 @@ type BoltDBStore struct {
db *bbolt.DB
}

// defaultOpenTimeout is the default timeout for performing flock on a bbolt database.
// bbolt does retries every 50ms during this interval.
const defaultOpenTimeout = 1 * time.Second

// NewBoltDBStore returns a new ready to use BoltDB storage with created bucket.
func NewBoltDBStore(cfg dbconfig.BoltDBOptions) (*BoltDBStore, error) {
cp := *bbolt.DefaultOptions // Do not change bbolt's global variable.
Expand All @@ -34,6 +39,8 @@ func NewBoltDBStore(cfg dbconfig.BoltDBOptions) (*BoltDBStore, error) {
return nil, err
}
}
opts.Timeout = defaultOpenTimeout

db, err := bbolt.Open(fileName, fileMode, opts)
if err != nil {
return nil, fmt.Errorf("failed to open BoltDB instance: %w", err)
Expand Down

0 comments on commit f1c6b9f

Please sign in to comment.