Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: Use timeout for boltdb database opening #3148

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading