Fix: write msg cache multiple times (#812)

Co-authored-by: john.xu <john.xu@bytedance.com>
This commit is contained in:
John Smith 2020-07-17 17:34:40 +08:00 committed by GitHub
parent e6aa452b51
commit 02c7fd8d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,11 +115,16 @@ 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]
defer func() { ret, err, shared := r.group.Do(q.String(), func() (interface{}, error) {
if msg == nil { isIPReq := isIPRequest(q)
return if isIPReq {
return r.fallbackExchange(m)
} }
msg, err := r.batchExchange(r.main, m)
if err != nil {
return nil, err
}
putMsgToCache(r.lruCache, q.String(), msg) putMsgToCache(r.lruCache, q.String(), msg)
if r.mapping || r.fakeip { if r.mapping || r.fakeip {
ips := r.msgToIP(msg) ips := r.msgToIP(msg)
@ -127,15 +132,7 @@ func (r *Resolver) exchangeWithoutCache(m *D.Msg) (msg *D.Msg, err error) {
putMsgToCache(r.lruCache, ip.String(), msg) putMsgToCache(r.lruCache, ip.String(), msg)
} }
} }
}() return msg, nil
ret, err, shared := r.group.Do(q.String(), func() (interface{}, error) {
isIPReq := isIPRequest(q)
if isIPReq {
return r.fallbackExchange(m)
}
return r.batchExchange(r.main, m)
}) })
if err == nil { if err == nil {