arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Don't log errors when context done
Eduard S eduard@iden3.io
Wed, 23 Dec 2020 17:33:41 +0100
commit

35d598f564c6f258aaa26a9ec0c9123aa6dc4dee

parent

8267d007c9732d6dbfbeddc3ac3cec25e800a7be

1 files changed, 20 insertions(+), 13 deletions(-)

jump to
M node/node.go → node/node.go

@@ -4,7 +4,6 @@ import (

"context" "fmt" "net/http" - "strings" "sync" "time"

@@ -409,22 +408,17 @@ }

// TODO(Edu): Consider keeping the `lastBlock` inside synchronizer so that we // don't have to pass it around. -func (n *Node) syncLoopFn(lastBlock *common.Block) (*common.Block, time.Duration) { - blockData, discarded, err := n.sync.Sync2(n.ctx, lastBlock) +func (n *Node) syncLoopFn(ctx context.Context, lastBlock *common.Block) (*common.Block, time.Duration, error) { + blockData, discarded, err := n.sync.Sync2(ctx, lastBlock) stats := n.sync.Stats() if err != nil { // case: error - if strings.Contains(err.Error(), "context canceled") { - log.Warnw("Synchronizer.Sync", "err", err) - } else { - log.Errorw("Synchronizer.Sync", "err", err) - } - return nil, n.cfg.Synchronizer.SyncLoopInterval.Duration + return nil, n.cfg.Synchronizer.SyncLoopInterval.Duration, err } else if discarded != nil { // case: reorg log.Infow("Synchronizer.Sync reorg", "discarded", *discarded) n.handleReorg(stats) - return nil, time.Duration(0) + return nil, time.Duration(0), nil } else if blockData != nil { // case: new block n.handleNewBlock(stats, synchronizer.SCVariablesPtr{

@@ -432,10 +426,10 @@ Rollup: blockData.Rollup.Vars,

Auction: blockData.Auction.Vars, WDelayer: blockData.WDelayer.Vars, }, blockData.Rollup.Batches) - return &blockData.Block, time.Duration(0) + return &blockData.Block, time.Duration(0), nil } else { // case: no block - return lastBlock, n.cfg.Synchronizer.SyncLoopInterval.Duration + return lastBlock, n.cfg.Synchronizer.SyncLoopInterval.Duration, nil } }

@@ -454,6 +448,7 @@ n.handleNewBlock(stats, vars, []common.BatchData{})

n.wg.Add(1) go func() { + var err error var lastBlock *common.Block waitDuration := time.Duration(0) for {

@@ -463,7 +458,13 @@ log.Info("Synchronizer done")

n.wg.Done() return case <-time.After(waitDuration): - lastBlock, waitDuration = n.syncLoopFn(lastBlock) + if lastBlock, waitDuration, err = n.syncLoopFn(n.ctx, + lastBlock); err != nil { + if n.ctx.Err() != nil { + continue + } + log.Errorw("Synchronizer.Sync", "err", err) + } } } }()

@@ -496,6 +497,9 @@ log.Info("DebugAPI routine stopped")

n.wg.Done() }() if err := n.debugAPI.Run(n.ctx); err != nil { + if n.ctx.Err() != nil { + return + } log.Fatalw("DebugAPI.Run", "err", err) } }()

@@ -511,6 +515,9 @@ log.Info("NodeAPI routine stopped")

n.wg.Done() }() if err := n.nodeAPI.Run(n.ctx); err != nil { + if n.ctx.Err() != nil { + return + } log.Fatalw("NodeAPI.Run", "err", err) } }()