@@ -32,30 +32,33 @@ import (
32
32
const (
33
33
// Size of cache for recent chainsync cursors
34
34
cursorCacheSize = 20
35
+
36
+ maxAutoReconnectDelay = 60 * time .Second
35
37
)
36
38
37
39
type ChainSync struct {
38
- oConn * ouroboros.Connection
39
- logger plugin.Logger
40
- network string
41
- networkMagic uint32
42
- address string
43
- socketPath string
44
- ntcTcp bool
45
- bulkMode bool
46
- intersectTip bool
47
- intersectPoints []ocommon.Point
48
- includeCbor bool
49
- autoReconnect bool
50
- statusUpdateFunc StatusUpdateFunc
51
- status * ChainSyncStatus
52
- errorChan chan error
53
- eventChan chan event.Event
54
- bulkRangeStart ocommon.Point
55
- bulkRangeEnd ocommon.Point
56
- cursorCache []ocommon.Point
57
- dialAddress string
58
- dialFamily string
40
+ oConn * ouroboros.Connection
41
+ logger plugin.Logger
42
+ network string
43
+ networkMagic uint32
44
+ address string
45
+ socketPath string
46
+ ntcTcp bool
47
+ bulkMode bool
48
+ intersectTip bool
49
+ intersectPoints []ocommon.Point
50
+ includeCbor bool
51
+ autoReconnect bool
52
+ autoReconnectDelay time.Duration
53
+ statusUpdateFunc StatusUpdateFunc
54
+ status * ChainSyncStatus
55
+ errorChan chan error
56
+ eventChan chan event.Event
57
+ bulkRangeStart ocommon.Point
58
+ bulkRangeEnd ocommon.Point
59
+ cursorCache []ocommon.Point
60
+ dialAddress string
61
+ dialFamily string
59
62
}
60
63
61
64
type ChainSyncStatus struct {
@@ -220,10 +223,20 @@ func (c *ChainSync) setupConnection() error {
220
223
err , ok := <- c .oConn .ErrorChan ()
221
224
if ok {
222
225
if c .autoReconnect {
226
+ c .autoReconnectDelay = 0
223
227
if c .logger != nil {
224
228
c .logger .Infof ("reconnecting to %s due to error: %s" , c .dialAddress , err )
225
229
}
226
230
for {
231
+ if c .autoReconnectDelay > 0 {
232
+ c .logger .Infof ("waiting %s to reconnect" , c .autoReconnectDelay )
233
+ time .Sleep (c .autoReconnectDelay )
234
+ // Double current reconnect delay up to maximum
235
+ c .autoReconnectDelay = min (c .autoReconnectDelay * 2 , maxAutoReconnectDelay )
236
+ } else {
237
+ // Set initial reconnect delay
238
+ c .autoReconnectDelay = 1 * time .Second
239
+ }
227
240
// Shutdown current connection
228
241
if err := c .oConn .Close (); err != nil {
229
242
if c .logger != nil {
0 commit comments