mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 10:18:50 +02:00
Fix timers
This commit is contained in:
parent
5b86a7f3f2
commit
f7d8d03e55
@ -360,10 +360,14 @@ func (conn *ConnectorICE) waitForReconnectTry() bool {
|
|||||||
minWait := 500
|
minWait := 500
|
||||||
maxWait := 2000
|
maxWait := 2000
|
||||||
duration := time.Duration(rand.Intn(maxWait-minWait)+minWait) * time.Millisecond
|
duration := time.Duration(rand.Intn(maxWait-minWait)+minWait) * time.Millisecond
|
||||||
|
|
||||||
|
timeout := time.NewTimer(duration)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-conn.ctx.Done():
|
case <-conn.ctx.Done():
|
||||||
return false
|
return false
|
||||||
case <-time.After(duration):
|
case <-timeout.C:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,10 +108,14 @@ func (conn *ConnectorRelay) waitForReconnectTry() bool {
|
|||||||
minWait := 500
|
minWait := 500
|
||||||
maxWait := 2000
|
maxWait := 2000
|
||||||
duration := time.Duration(rand.Intn(maxWait-minWait)+minWait) * time.Millisecond
|
duration := time.Duration(rand.Intn(maxWait-minWait)+minWait) * time.Millisecond
|
||||||
|
|
||||||
|
timeout := time.NewTimer(duration)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-conn.ctx.Done():
|
case <-conn.ctx.Done():
|
||||||
return false
|
return false
|
||||||
case <-time.After(duration):
|
case <-timeout.C:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,6 @@ func (h *Handshaker) Handshake(args HandshakeArgs) (*OfferAnswer, error) {
|
|||||||
// OnRemoteOffer handles an offer from the remote peer and returns true if the message was accepted, false otherwise
|
// OnRemoteOffer handles an offer from the remote peer and returns true if the message was accepted, false otherwise
|
||||||
// doesn't block, discards the message if connection wasn't ready
|
// doesn't block, discards the message if connection wasn't ready
|
||||||
func (h *Handshaker) OnRemoteOffer(offer OfferAnswer) bool {
|
func (h *Handshaker) OnRemoteOffer(offer OfferAnswer) bool {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case h.remoteOffersCh <- offer:
|
case h.remoteOffersCh <- offer:
|
||||||
return true
|
return true
|
||||||
@ -173,6 +172,9 @@ func (h *Handshaker) sendAnswer() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handshaker) waitForRemoteOfferConfirmation() (*OfferAnswer, error) {
|
func (h *Handshaker) waitForRemoteOfferConfirmation() (*OfferAnswer, error) {
|
||||||
|
timeout := time.NewTimer(h.config.Timeout)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case remoteOfferAnswer := <-h.remoteOffersCh:
|
case remoteOfferAnswer := <-h.remoteOffersCh:
|
||||||
// received confirmation from the remote peer -> ready to proceed
|
// received confirmation from the remote peer -> ready to proceed
|
||||||
@ -183,7 +185,7 @@ func (h *Handshaker) waitForRemoteOfferConfirmation() (*OfferAnswer, error) {
|
|||||||
return &remoteOfferAnswer, nil
|
return &remoteOfferAnswer, nil
|
||||||
case remoteOfferAnswer := <-h.remoteAnswerCh:
|
case remoteOfferAnswer := <-h.remoteAnswerCh:
|
||||||
return &remoteOfferAnswer, nil
|
return &remoteOfferAnswer, nil
|
||||||
case <-time.After(h.config.Timeout):
|
case <-timeout.C:
|
||||||
return nil, NewConnectionTimeoutError(h.config.Key, h.config.Timeout)
|
return nil, NewConnectionTimeoutError(h.config.Key, h.config.Timeout)
|
||||||
case <-h.ctx.Done():
|
case <-h.ctx.Done():
|
||||||
// closed externally
|
// closed externally
|
||||||
|
@ -24,8 +24,11 @@ func NewGuard(context context.Context, relayClient *Client) *Guard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Guard) OnDisconnected() {
|
func (g *Guard) OnDisconnected() {
|
||||||
|
timeout := time.NewTimer(reconnectingTimeout)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Second):
|
case <-timeout.C:
|
||||||
_ = g.relayClient.Connect()
|
_ = g.relayClient.Connect()
|
||||||
case <-g.ctx.Done():
|
case <-g.ctx.Done():
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user