Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1818786: Fix handling of delay in acquiring lease with stp turned on #28

Merged
merged 1 commit into from Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion plugins/ipam/dhcp/daemon.go
Expand Up @@ -34,7 +34,6 @@ import (
)

const listenFdsStart = 3
const resendCount = 3

var errNoMoreTries = errors.New("no more tries")

Expand Down
13 changes: 10 additions & 3 deletions plugins/ipam/dhcp/lease.go
Expand Up @@ -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
Expand Down Expand Up @@ -325,19 +325,26 @@ 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
}

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
}
}

Expand Down