Skip to content

Commit

Permalink
exporter: fix rare deadlock in el payload exporter (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
invis-bitfly authored May 21, 2024
1 parent e4beb95 commit dca074c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions backend/pkg/exporter/modules/execution_payloads_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (d *executionPayloadsExporter) OnFinalizedCheckpoint(event *constypes.Stand
return err
}

log.Debugf("updating execution payloads cached view took %v", time.Since(start))
log.Infof("updating execution payloads cached view took %v", time.Since(start))
return nil
}

Expand Down Expand Up @@ -139,22 +139,22 @@ func (d *executionPayloadsExporter) maintainTable() (err error) {
}
resData := make([]Result, 0, maxBlock-minBlock+1)

ctx, finish := context.WithCancel(context.Background())
defer finish()
ctx, abortProcessing := context.WithCancel(context.Background())
defer abortProcessing() // to kill the errgroup if something goes wrong
group, _ := errgroup.WithContext(ctx)

// coroutine to process the blocks
group.Go(func() error {
var block *types.Eth1BlockIndexed
for i := minBlock; i <= maxBlock; i++ {
for {
select {
case <-ctx.Done():
return ctx.Err()
case b, ok := <-blockChan:
block = b
if !ok {
return nil
}
block = b
}
// read txn reward
raw := block.GetTxReward()
Expand All @@ -175,16 +175,16 @@ func (d *executionPayloadsExporter) maintainTable() (err error) {
}
resData = append(resData, Result{BlockHash: hash, FeeRecipientReward: dec})
}
return nil
})

err = db.BigtableClient.StreamBlocksIndexedDescending(blockChan, maxBlock, minBlock)

if err != nil {
finish()
abortProcessing()
return fmt.Errorf("error streaming blocks: %w", err)
}

close(blockChan) // possible deadlock if not closed
err = group.Wait()

if err != nil {
Expand Down

0 comments on commit dca074c

Please sign in to comment.