Fix: dns should put msg to cache while exchangeWithoutCache (#820)

This commit is contained in:
Kr328 2020-07-20 21:16:36 +08:00 committed by GitHub
parent ae1e1dc9f6
commit 20eff200b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,24 +115,29 @@ func (r *Resolver) Exchange(m *D.Msg) (msg *D.Msg, err error) {
func (r *Resolver) exchangeWithoutCache(m *D.Msg) (msg *D.Msg, err error) { func (r *Resolver) exchangeWithoutCache(m *D.Msg) (msg *D.Msg, err error) {
q := m.Question[0] q := m.Question[0]
ret, err, shared := r.group.Do(q.String(), func() (interface{}, error) { ret, err, shared := r.group.Do(q.String(), func() (result interface{}, err error) {
defer func() {
if err != nil {
return
}
msg := result.(*D.Msg)
putMsgToCache(r.lruCache, q.String(), msg)
if r.mapping || r.fakeip {
ips := r.msgToIP(msg)
for _, ip := range ips {
putMsgToCache(r.lruCache, ip.String(), msg)
}
}
}()
isIPReq := isIPRequest(q) isIPReq := isIPRequest(q)
if isIPReq { if isIPReq {
return r.fallbackExchange(m) return r.fallbackExchange(m)
} }
msg, err := r.batchExchange(r.main, m) return r.batchExchange(r.main, m)
if err != nil {
return nil, err
}
putMsgToCache(r.lruCache, q.String(), msg)
if r.mapping || r.fakeip {
ips := r.msgToIP(msg)
for _, ip := range ips {
putMsgToCache(r.lruCache, ip.String(), msg)
}
}
return msg, nil
}) })
if err == nil { if err == nil {