From 295e02e4e920f5053c93639323949f63b34b522a Mon Sep 17 00:00:00 2001 From: Eugene Yakubovich Date: Mon, 15 Jun 2015 12:40:34 -0700 Subject: [PATCH] dhcp: decrease read timeout and clamp backoff --- plugins/ipam/dhcp/lease.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/ipam/dhcp/lease.go b/plugins/ipam/dhcp/lease.go index fe23fb09..361e33a2 100644 --- a/plugins/ipam/dhcp/lease.go +++ b/plugins/ipam/dhcp/lease.go @@ -34,6 +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 ( leaseStateBound = iota @@ -308,7 +309,9 @@ func backoffRetry(f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) { time.Sleep(baseDelay + jitter(time.Second)) - baseDelay *= 2 + if baseDelay < resendDelayMax { + baseDelay *= 2 + } } return nil, errNoMoreTries @@ -322,7 +325,7 @@ func newDHCPClient(link netlink.Link) (*dhcp4client.Client, error) { return dhcp4client.New( dhcp4client.HardwareAddr(link.Attrs().HardwareAddr), - dhcp4client.Timeout(10*time.Second), + dhcp4client.Timeout(5*time.Second), dhcp4client.Broadcast(false), dhcp4client.Connection(pktsock), )