Skip to content

Commit

Permalink
sentry: handle "retry later" grpc stream (erigontech#6852)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored and calmbeing committed Mar 16, 2023
1 parent c03176a commit 88b28d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 1 addition & 2 deletions cl/cltypes/lightclient_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package cltypes_test

import (
"testing"

_ "embed"
"testing"

libcommon "github.com/ledgerwatch/erigon-lib/common"

Expand Down
29 changes: 23 additions & 6 deletions cmd/lightclient/lightclient/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"sync"
"time"

"github.com/ledgerwatch/erigon-lib/gointerfaces/grpcutil"
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
Expand Down Expand Up @@ -46,20 +48,35 @@ func (c *ChainTipSubscriber) StartLoop() {
}
log.Info("[LightClient Gossip] Started Gossip")
c.started = true

Retry:
for {
if err := c.subscribeGossip(); err != nil {
if errors.Is(err, context.Canceled) {
return
}
if grpcutil.IsRetryLater(err) || grpcutil.IsEndOfStream(err) {
time.Sleep(3 * time.Second)
continue Retry
}

log.Warn("[Lightclient] could not read gossip :/", "reason", err)
time.Sleep(time.Second)
}
}
}

func (c *ChainTipSubscriber) subscribeGossip() error {
stream, err := c.sentinel.SubscribeGossip(c.ctx, &sentinel.EmptyMessage{})
if err != nil {
log.Warn("could not start lightclient", "reason", err)
return
return err
}
defer stream.CloseSend()

for {
data, err := stream.Recv()
if err != nil {
if !errors.Is(err, context.Canceled) {
log.Debug("[Lightclient] could not read gossip :/", "reason", err)
}
continue
return err
}
if err := c.handleGossipData(data); err != nil {
log.Warn("could not process new gossip",
Expand Down

0 comments on commit 88b28d4

Please sign in to comment.