mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-09 10:49:35 +08:00
chore: better dns background fetch retrying
This commit is contained in:
parent
71ab8298a2
commit
821e908e48
@ -149,6 +149,16 @@ func (r *Resolver) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, e
|
||||
if len(m.Question) == 0 {
|
||||
return nil, errors.New("should have one question at least")
|
||||
}
|
||||
continueFetch := false
|
||||
defer func() {
|
||||
if continueFetch || errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), resolver.DefaultDNSTimeout)
|
||||
defer cancel()
|
||||
go func() {
|
||||
_, _ = r.exchangeWithoutCache(ctx, m) // ignore result, just for putMsgToCache
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
q := m.Question[0]
|
||||
cacheM, expireTime, hit := r.lruCache.GetWithExpire(q.String())
|
||||
@ -157,7 +167,7 @@ func (r *Resolver) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, e
|
||||
msg = cacheM.Copy()
|
||||
if expireTime.Before(now) {
|
||||
setMsgTTL(msg, uint32(1)) // Continue fetch
|
||||
go r.exchangeWithoutCache(ctx, m)
|
||||
continueFetch = true
|
||||
} else {
|
||||
setMsgTTL(msg, uint32(time.Until(expireTime).Seconds()))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user