Merge pull request #501 from aneeshkp/dhcp-timeout

Fix handling of delay in acquiring lease with stp turned on
This commit is contained in:
Bryan Boreham 2020-07-01 16:46:06 +01:00 committed by GitHub
commit 28773dc925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

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

View File

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