Skip to content

Commit 81c7936

Browse files
sentry: handle "retry later" grpc stream (#6852)
1 parent 43960fe commit 81c7936

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

cl/cltypes/lightclient_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package cltypes_test
22

33
import (
4-
"testing"
5-
64
_ "embed"
5+
"testing"
76

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

cmd/lightclient/lightclient/subscriber.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"errors"
66
"fmt"
77
"sync"
8+
"time"
89

10+
"github.com/ledgerwatch/erigon-lib/gointerfaces/grpcutil"
911
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
1012
"github.com/ledgerwatch/erigon/cl/clparams"
1113
"github.com/ledgerwatch/erigon/cl/cltypes"
@@ -46,20 +48,35 @@ func (c *ChainTipSubscriber) StartLoop() {
4648
}
4749
log.Info("[LightClient Gossip] Started Gossip")
4850
c.started = true
51+
52+
Retry:
53+
for {
54+
if err := c.subscribeGossip(); err != nil {
55+
if errors.Is(err, context.Canceled) {
56+
return
57+
}
58+
if grpcutil.IsRetryLater(err) || grpcutil.IsEndOfStream(err) {
59+
time.Sleep(3 * time.Second)
60+
continue Retry
61+
}
62+
63+
log.Warn("[Lightclient] could not read gossip :/", "reason", err)
64+
time.Sleep(time.Second)
65+
}
66+
}
67+
}
68+
69+
func (c *ChainTipSubscriber) subscribeGossip() error {
4970
stream, err := c.sentinel.SubscribeGossip(c.ctx, &sentinel.EmptyMessage{})
5071
if err != nil {
51-
log.Warn("could not start lightclient", "reason", err)
52-
return
72+
return err
5373
}
5474
defer stream.CloseSend()
5575

5676
for {
5777
data, err := stream.Recv()
5878
if err != nil {
59-
if !errors.Is(err, context.Canceled) {
60-
log.Debug("[Lightclient] could not read gossip :/", "reason", err)
61-
}
62-
continue
79+
return err
6380
}
6481
if err := c.handleGossipData(data); err != nil {
6582
log.Warn("could not process new gossip",

0 commit comments

Comments
 (0)