Fix: write msg cache multiple times (#812)

Co-authored-by: john.xu <john.xu@bytedance.com>
This commit is contained in:
gVisor bot 2020-07-17 17:34:40 +08:00
parent 22f32c3789
commit 63e2c176f1

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 {