Fix handling of delay in acquiring lease with stp turned on

Signed-off-by: Aneesh Puttur <aneeshputtur@gmail.com>
This commit is contained in:
Aneesh Puttur 2020-06-18 12:35:23 -04:00
parent e1f8f9bee5
commit d4775ecff5
2 changed files with 10 additions and 4 deletions

View File

@ -34,7 +34,6 @@ import (
) )
const listenFdsStart = 3 const listenFdsStart = 3
const resendCount = 3
var errNoMoreTries = errors.New("no more tries") var errNoMoreTries = errors.New("no more tries")

View File

@ -34,7 +34,7 @@ import (
// RFC 2131 suggests using exponential backoff, starting with 4sec // RFC 2131 suggests using exponential backoff, starting with 4sec
// and randomized to +/- 1sec // and randomized to +/- 1sec
const resendDelay0 = 4 * time.Second const resendDelay0 = 4 * time.Second
const resendDelayMax = 32 * time.Second const resendDelayMax = 62 * time.Second
const ( const (
leaseStateBound = iota leaseStateBound = iota
@ -335,8 +335,9 @@ func jitter(span time.Duration) time.Duration {
func backoffRetry(f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) { func backoffRetry(f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) {
var baseDelay time.Duration = resendDelay0 var baseDelay time.Duration = resendDelay0
var sleepTime time.Duration
for i := 0; i < resendCount; i++ { for {
pkt, err := f() pkt, err := f()
if err == nil { if err == nil {
return pkt, nil return pkt, nil
@ -344,10 +345,16 @@ func backoffRetry(f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) {
log.Print(err) log.Print(err)
time.Sleep(baseDelay + jitter(time.Second)) sleepTime = baseDelay + jitter(time.Second)
log.Printf("retrying in %f seconds", sleepTime.Seconds())
time.Sleep(sleepTime)
if baseDelay < resendDelayMax { if baseDelay < resendDelayMax {
baseDelay *= 2 baseDelay *= 2
} else {
break
} }
} }