Skip to content

Commit

Permalink
fix(node): close localstore if migration errors out (#4841)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Oct 3, 2024
1 parent 19481d9 commit 47e1f98
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/storer/storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func initDiskRepository(

err = migration.Migrate(store, "core-migration", localmigration.BeforeInitSteps(store))
if err != nil {
return nil, nil, nil, fmt.Errorf("failed core migration: %w", err)
return nil, nil, nil, errors.Join(store.Close(), fmt.Errorf("failed core migration: %w", err))
}

if opts.LdbStats.Load() != nil {
Expand Down Expand Up @@ -482,6 +482,12 @@ func New(ctx context.Context, dirPath string, opts *Options) (*DB, error) {
}
}

defer func() {
if err != nil && dbCloser != nil {
err = errors.Join(err, dbCloser.Close())
}
}()

sharkyBasePath := ""
if dirPath != "" {
sharkyBasePath = path.Join(dirPath, sharkyPath)
Expand All @@ -495,7 +501,7 @@ func New(ctx context.Context, dirPath string, opts *Options) (*DB, error) {
)
})
if err != nil {
return nil, err
return nil, fmt.Errorf("failed regular migration: %w", err)
}

cacheObj, err := cache.New(ctx, st.IndexStore(), opts.CacheCapacity)
Expand Down

0 comments on commit 47e1f98

Please sign in to comment.