Skip to content

Commit 4abf06d

Browse files
committed
Optimize for wake-up from hibernation
1. Give time to NIC to be ready. 2. Avoid peak request times.
1 parent 324786d commit 4abf06d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

dnscrypt-proxy/proxy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (proxy *Proxy) StartProxy() {
324324
if liveServers == 0 {
325325
delay = proxy.certRefreshDelayAfterFailure
326326
}
327-
clocksmith.Sleep(delay)
327+
sleepIncludeInertia(delay)
328328
liveServers, _ = proxy.serversInfo.refresh(proxy)
329329
if liveServers > 0 {
330330
proxy.certIgnoreTimestamp = false
@@ -335,6 +335,16 @@ func (proxy *Proxy) StartProxy() {
335335
}
336336
}
337337

338+
func sleepIncludeInertia(duration time.Duration) {
339+
// When restoring from hibernation, the NIC (Network Interface Card) needs time to get ready.
340+
nicInitDelay := time.Minute
341+
if duration > nicInitDelay {
342+
clocksmith.Sleep(duration - nicInitDelay)
343+
duration = nicInitDelay
344+
}
345+
time.Sleep(duration) // Frozen during this?! Lower probability.
346+
}
347+
338348
func (proxy *Proxy) updateRegisteredServers() error {
339349
for _, source := range proxy.sources {
340350
registeredServers, err := source.Parse()

0 commit comments

Comments
 (0)