diff --git a/pkg/core/storage/boltdb_store.go b/pkg/core/storage/boltdb_store.go index a874dbd8c..535db8b8f 100644 --- a/pkg/core/storage/boltdb_store.go +++ b/pkg/core/storage/boltdb_store.go @@ -56,7 +56,12 @@ func NewBoltDBStore(cfg dbconfig.BoltDBOptions) (*BoltDBStore, error) { }) } if err != nil { - return nil, fmt.Errorf("failed to initialize BoltDB instance: %w", err) + closeErr := db.Close() + err = fmt.Errorf("failed to initialize BoltDB instance: %w", err) + if closeErr != nil { + err = fmt.Errorf("%w, failed to close BoltDB instance: %v", err, closeErr) + } + return nil, err } return &BoltDBStore{db: db}, nil diff --git a/pkg/core/storage/boltdb_store_test.go b/pkg/core/storage/boltdb_store_test.go index a877b4e38..99f0242b1 100644 --- a/pkg/core/storage/boltdb_store_test.go +++ b/pkg/core/storage/boltdb_store_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/stretchr/testify/require" "go.etcd.io/bbolt" ) @@ -47,10 +46,9 @@ func TestROBoltDB(t *testing.T) { require.NoError(t, store.Close()) // Create the DB without buckets and try to open it in RO mode, an error is expected. - fileMode := os.FileMode(0600) - cfg.FilePath = filepath.Join(d, "clean_ro_bolt_db") - require.NoError(t, io.MakeDirForFile(cfg.FilePath, "BoltDB")) - db, err := bbolt.Open(cfg.FilePath, fileMode, nil) + tmp := t.TempDir() + cfg.FilePath = filepath.Join(tmp, "clean_ro_bolt") + db, err := bbolt.Open(cfg.FilePath, os.FileMode(0600), nil) require.NoError(t, err) require.NoError(t, db.Close())