plugin/forward: check message Id when reading from upstream server
@@ -103,8 +103,10 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options
return nil, err
}
+ var ret *dns.Msg
conn.SetReadDeadline(time.Now().Add(readTimeout))
- ret, err := conn.ReadMsg()
+ for {
+ ret, err = conn.ReadMsg()
if err != nil {
conn.Close() // not giving it back
if err == io.EOF && cached {
@@ -112,6 +114,11 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options
}
return ret, err
}
+ // drop out-of-order responses
+ if state.Req.Id == ret.Id {
+ break
+ }
+ }
p.transport.Yield(conn)
