From b0fed73236f74bbaf031437aedead5dde824f18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?YuSaki=E4=B8=B6Kanade?= <53483352+Nep-Timeline@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:30:57 +0800 Subject: [PATCH] Fix: mapping dns should not stale (#675) * Fix: mapping dns should not stale * Update enhancer.go --- dns/enhancer.go | 2 +- dns/middleware.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dns/enhancer.go b/dns/enhancer.go index 76d4460e..ab144fd3 100644 --- a/dns/enhancer.go +++ b/dns/enhancer.go @@ -109,7 +109,7 @@ func NewEnhancer(cfg Config) *ResolverEnhancer { if cfg.EnhancedMode != C.DNSNormal { fakePool = cfg.Pool - mapping = cache.New(cache.WithSize[netip.Addr, string](4096), cache.WithStale[netip.Addr, string](true)) + mapping = cache.New(cache.WithSize[netip.Addr, string](4096)) } return &ResolverEnhancer{ diff --git a/dns/middleware.go b/dns/middleware.go index f2dd9c96..695432da 100644 --- a/dns/middleware.go +++ b/dns/middleware.go @@ -129,6 +129,10 @@ func withMapping(mapping *cache.LruCache[netip.Addr, string]) middleware { continue } + if ttl < 1 { + ttl = 1 + } + mapping.SetWithExpire(ip, host, time.Now().Add(time.Second*time.Duration(ttl))) }