From fe88e901812727284c97077b4f6d46ae3bccedb0 Mon Sep 17 00:00:00 2001 From: i-norden Date: Wed, 31 May 2023 18:07:14 -0500 Subject: [PATCH] avoid overshadowing err in defers --- pkg/snapshot/pg/publisher.go | 3 ++- pkg/snapshot/service.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/snapshot/pg/publisher.go b/pkg/snapshot/pg/publisher.go index b928934..e58cc29 100644 --- a/pkg/snapshot/pg/publisher.go +++ b/pkg/snapshot/pg/publisher.go @@ -110,6 +110,7 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) { return err } tx := pubTx{snapTx, nil} + // we must avoid overshadowing the `err` defer func() { err = snapt.CommitOrRollback(tx, err) if err != nil { @@ -117,7 +118,7 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) { } }() - if err := tx.publishIPLD(headerNode.Cid(), headerNode.RawData(), header.Number); err != nil { + if err = tx.publishIPLD(headerNode.Cid(), headerNode.RawData(), header.Number); err != nil { return err } diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index 0517af0..a8da899 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -200,8 +200,12 @@ func (s *Service) createSnapshot(ctx context.Context, it trie.NodeIterator, head if err != nil { return err } + // we must avoid overshadowing the `err` defer func() { err = CommitOrRollback(tx, err) + if err != nil { + log.Errorf("CommitOrRollback failed: %s", err) + } }() // path (from recovery dump) to be seeked on recovery