mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-24 19:51:33 +02:00
Add retry to sending signal message (#906)
Increased the default send timeout from 2 to 5 Added a max of 4 retries with an increased timeout after the second attempt using the grpc client context and checking the error value for canceled context
This commit is contained in:
parent
d2db6bd03e
commit
7f454f9c00
@ -24,6 +24,8 @@ import (
|
|||||||
"github.com/netbirdio/netbird/signal/proto"
|
"github.com/netbirdio/netbird/signal/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultSendTimeout = 5 * time.Second
|
||||||
|
|
||||||
// ConnStateNotifier is a wrapper interface of the status recorder
|
// ConnStateNotifier is a wrapper interface of the status recorder
|
||||||
type ConnStateNotifier interface {
|
type ConnStateNotifier interface {
|
||||||
MarkSignalDisconnected()
|
MarkSignalDisconnected()
|
||||||
@ -322,14 +324,28 @@ func (c *GrpcClient) Send(msg *proto.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
|
attemptTimeout := defaultSendTimeout
|
||||||
defer cancel()
|
|
||||||
_, err = c.realClient.Send(ctx, encryptedMessage)
|
for attempt := 0; attempt < 4; attempt++ {
|
||||||
if err != nil {
|
if attempt > 1 {
|
||||||
return err
|
attemptTimeout = time.Duration(attempt) * 5 * time.Second
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(c.ctx, attemptTimeout)
|
||||||
|
|
||||||
|
_, err = c.realClient.Send(ctx, encryptedMessage)
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// receive receives messages from other peers coming through the Signal Exchange
|
// receive receives messages from other peers coming through the Signal Exchange
|
||||||
|
Loading…
x
Reference in New Issue
Block a user