dhcp ipam: add fast retry
Almost every first retry of DHCP will fail due to interface is not up. Add a fast retry to reduce unnecessary latency. Signed-off-by: SilverBut <SilverBut@users.noreply.github.com>
This commit is contained in:
parent
2bebd89aa2
commit
4b216e9d9b
@ -423,6 +423,7 @@ func jitter(span time.Duration) time.Duration {
|
||||
func backoffRetry(resendMax time.Duration, f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) {
|
||||
var baseDelay time.Duration = resendDelay0
|
||||
var sleepTime time.Duration
|
||||
var fastRetryLimit = 3 // fast retry for 3 times to speed up
|
||||
|
||||
for {
|
||||
pkt, err := f()
|
||||
@ -432,7 +433,12 @@ func backoffRetry(resendMax time.Duration, f func() (*dhcp4.Packet, error)) (*dh
|
||||
|
||||
log.Print(err)
|
||||
|
||||
if fastRetryLimit == 0 {
|
||||
sleepTime = baseDelay + jitter(time.Second)
|
||||
} else {
|
||||
sleepTime = jitter(time.Second)
|
||||
fastRetryLimit--
|
||||
}
|
||||
|
||||
log.Printf("retrying in %f seconds", sleepTime.Seconds())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user