Browse Source

Don't log errors when context done

feature/sql-semaphore1
Eduard S 3 years ago
parent
commit
35d598f564
1 changed files with 20 additions and 13 deletions
  1. +20
    -13
      node/node.go

+ 20
- 13
node/node.go

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"net/http" "net/http"
"strings"
"sync" "sync"
"time" "time"
@ -409,22 +408,17 @@ func (n *Node) handleReorg(stats *synchronizer.Stats) {
// TODO(Edu): Consider keeping the `lastBlock` inside synchronizer so that we // TODO(Edu): Consider keeping the `lastBlock` inside synchronizer so that we
// don't have to pass it around. // 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() stats := n.sync.Stats()
if err != nil { if err != nil {
// case: error // 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 { } else if discarded != nil {
// case: reorg // case: reorg
log.Infow("Synchronizer.Sync reorg", "discarded", *discarded) log.Infow("Synchronizer.Sync reorg", "discarded", *discarded)
n.handleReorg(stats) n.handleReorg(stats)
return nil, time.Duration(0)
return nil, time.Duration(0), nil
} else if blockData != nil { } else if blockData != nil {
// case: new block // case: new block
n.handleNewBlock(stats, synchronizer.SCVariablesPtr{ n.handleNewBlock(stats, synchronizer.SCVariablesPtr{
@ -432,10 +426,10 @@ func (n *Node) syncLoopFn(lastBlock *common.Block) (*common.Block, time.Duration
Auction: blockData.Auction.Vars, Auction: blockData.Auction.Vars,
WDelayer: blockData.WDelayer.Vars, WDelayer: blockData.WDelayer.Vars,
}, blockData.Rollup.Batches) }, blockData.Rollup.Batches)
return &blockData.Block, time.Duration(0)
return &blockData.Block, time.Duration(0), nil
} else { } else {
// case: no block // case: no block
return lastBlock, n.cfg.Synchronizer.SyncLoopInterval.Duration
return lastBlock, n.cfg.Synchronizer.SyncLoopInterval.Duration, nil
} }
} }
@ -454,6 +448,7 @@ func (n *Node) StartSynchronizer() {
n.wg.Add(1) n.wg.Add(1)
go func() { go func() {
var err error
var lastBlock *common.Block var lastBlock *common.Block
waitDuration := time.Duration(0) waitDuration := time.Duration(0)
for { for {
@ -463,7 +458,13 @@ func (n *Node) StartSynchronizer() {
n.wg.Done() n.wg.Done()
return return
case <-time.After(waitDuration): 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 @@ func (n *Node) StartDebugAPI() {
n.wg.Done() n.wg.Done()
}() }()
if err := n.debugAPI.Run(n.ctx); err != nil { if err := n.debugAPI.Run(n.ctx); err != nil {
if n.ctx.Err() != nil {
return
}
log.Fatalw("DebugAPI.Run", "err", err) log.Fatalw("DebugAPI.Run", "err", err)
} }
}() }()
@ -511,6 +515,9 @@ func (n *Node) StartNodeAPI() {
n.wg.Done() n.wg.Done()
}() }()
if err := n.nodeAPI.Run(n.ctx); err != nil { if err := n.nodeAPI.Run(n.ctx); err != nil {
if n.ctx.Err() != nil {
return
}
log.Fatalw("NodeAPI.Run", "err", err) log.Fatalw("NodeAPI.Run", "err", err)
} }
}() }()

Loading…
Cancel
Save