From 4abf06dca5a1efc0c539d11692113a1a17c1fe7a Mon Sep 17 00:00:00 2001 From: YX Hao Date: Tue, 11 Nov 2025 21:54:37 +0800 Subject: [PATCH] Optimize for wake-up from hibernation 1. Give time to NIC to be ready. 2. Avoid peak request times. --- dnscrypt-proxy/proxy.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index d20af29c57..162759d346 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -324,7 +324,7 @@ func (proxy *Proxy) StartProxy() { if liveServers == 0 { delay = proxy.certRefreshDelayAfterFailure } - clocksmith.Sleep(delay) + sleepIncludeInertia(delay) liveServers, _ = proxy.serversInfo.refresh(proxy) if liveServers > 0 { proxy.certIgnoreTimestamp = false @@ -335,6 +335,16 @@ func (proxy *Proxy) StartProxy() { } } +func sleepIncludeInertia(duration time.Duration) { + // When restoring from hibernation, the NIC (Network Interface Card) needs time to get ready. + nicInitDelay := time.Minute + if duration > nicInitDelay { + clocksmith.Sleep(duration - nicInitDelay) + duration = nicInitDelay + } + time.Sleep(duration) // Frozen during this?! Lower probability. +} + func (proxy *Proxy) updateRegisteredServers() error { for _, source := range proxy.sources { registeredServers, err := source.Parse()