mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-29 03:23:56 +01:00
feat: improve signal server reconnect logic
This commit is contained in:
parent
dd04cba8a7
commit
08554a0494
@ -65,16 +65,30 @@ func NewClient(addr string, ctx context.Context) (*Client, error) {
|
|||||||
func (client *Client) Receive(key string, msgHandler func(msg *proto.Message) error) {
|
func (client *Client) Receive(key string, msgHandler func(msg *proto.Message) error) {
|
||||||
client.connWg.Add(1)
|
client.connWg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
|
var backOff = &backoff.ExponentialBackOff{
|
||||||
|
InitialInterval: backoff.DefaultInitialInterval,
|
||||||
|
RandomizationFactor: backoff.DefaultRandomizationFactor,
|
||||||
|
Multiplier: backoff.DefaultMultiplier,
|
||||||
|
MaxInterval: 3 * time.Second,
|
||||||
|
MaxElapsedTime: time.Duration(0), //never stop
|
||||||
|
Stop: backoff.Stop,
|
||||||
|
Clock: backoff.SystemClock,
|
||||||
|
}
|
||||||
|
|
||||||
operation := func() error {
|
operation := func() error {
|
||||||
err := client.connect(key, msgHandler)
|
err := client.connect(key, msgHandler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("disconnected from the Signal Exchange due to an error %s. Retrying ... ", err)
|
log.Warnf("disconnected from the Signal Exchange due to an error %s. Retrying ... ", err)
|
||||||
client.connWg.Add(1)
|
client.connWg.Add(1)
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := backoff.Retry(operation, backoff.NewExponentialBackOff())
|
backOff.Reset()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := backoff.Retry(operation, backOff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error while communicating with the Signal Exchange %s ", err)
|
log.Errorf("error while communicating with the Signal Exchange %s ", err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user