From 47e1f9844bf7e2670e78c70a7e43c8e2389824c8 Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:03:25 +0300 Subject: [PATCH] fix(node): close localstore if migration errors out (#4841) --- pkg/storer/storer.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/storer/storer.go b/pkg/storer/storer.go index bf7e0f0dbc1..250fbad1f6d 100644 --- a/pkg/storer/storer.go +++ b/pkg/storer/storer.go @@ -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 { @@ -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) @@ -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)