From cfee849963ab7a27e9597c40aee1e903f8e55ce2 Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Wed, 10 Apr 2019 20:25:21 +0930 Subject: [PATCH] Change the single in flight key for Client.Exchange (#943) Previously it was possible for two different questions to hit the same single in flight entry if the type or class isn't in the relevant XToString map. This could happen for a proxy server or similar. --- client.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 20cafe27..b14c8d90 100644 --- a/client.go +++ b/client.go @@ -6,6 +6,7 @@ import ( "context" "crypto/tls" "encoding/binary" + "fmt" "io" "net" "strings" @@ -128,20 +129,15 @@ func (c *Client) Exchange(m *Msg, address string) (r *Msg, rtt time.Duration, er return c.exchange(m, address) } - t := "nop" - if t1, ok := TypeToString[m.Question[0].Qtype]; ok { - t = t1 - } - cl := "nop" - if cl1, ok := ClassToString[m.Question[0].Qclass]; ok { - cl = cl1 - } - r, rtt, err, shared := c.group.Do(m.Question[0].Name+t+cl, func() (*Msg, time.Duration, error) { + q := m.Question[0] + key := fmt.Sprintf("%s:%d:%d", q.Name, q.Qtype, q.Qclass) + r, rtt, err, shared := c.group.Do(key, func() (*Msg, time.Duration, error) { return c.exchange(m, address) }) if r != nil && shared { r = r.Copy() } + return r, rtt, err }