Skip to content

Commit

Permalink
Add some jitter to leafnode remotes reconnect (#4398)
Browse files Browse the repository at this point in the history
This adds a jitter delay based on the reconnect delay for when a remote
reconnects.
  • Loading branch information
neilalexander committed Aug 15, 2023
2 parents 8717b05 + 740e5dd commit c2d1e6d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/leafnode.go
Expand Up @@ -533,6 +533,8 @@ func (s *Server) connectToRemoteLeafNode(remote *leafNodeCfg, firstConnect bool)
}
}
if err != nil {
jitter := time.Duration(rand.Int63n(int64(reconnectDelay)))
delay := reconnectDelay + jitter
attempts++
if s.shouldReportConnectErr(firstConnect, attempts) {
s.Errorf(connErrFmt, rURL.Host, attempts, err)
Expand All @@ -542,7 +544,7 @@ func (s *Server) connectToRemoteLeafNode(remote *leafNodeCfg, firstConnect bool)
select {
case <-s.quitCh:
return
case <-time.After(reconnectDelay):
case <-time.After(delay):
// Check if we should migrate any JetStream assets while this remote is down.
s.checkJetStreamMigrate(remote)
continue
Expand Down

0 comments on commit c2d1e6d

Please sign in to comment.