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
1 changed files with 9 additions and 12 deletions

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) {
q := m.Question[0]
defer func() {
if msg == nil {
return
ret, err, shared := r.group.Do(q.String(), func() (interface{}, error) {
isIPReq := isIPRequest(q)
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)
if r.mapping || r.fakeip {
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)
}
}
}()
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)
return msg, nil
})
if err == nil {