[plugin/proxy]: Return on WriteMsg err. (#2096)

* [plugin/proxy]: Return on WriteMsg err.

Followup PR on the heels of #2050. Short-circut and log on error from
`WriteMsg`. This will prevent code getting stuck on `ReadMsg` and allow
for easier debugging.

Also simply the `ReadMsg` calling code a little - remove double `Close` (already called above).
This commit is contained in:
dilyevsky
2018-09-17 10:21:12 -07:00
committed by GitHub
parent 063999551d
commit 4ac06a342b

View File

@@ -89,15 +89,12 @@ func exchange(m *dns.Msg, co net.Conn) (*dns.Msg, error) {
writeDeadline := time.Now().Add(defaultTimeout)
dnsco.SetWriteDeadline(writeDeadline)
dnsco.WriteMsg(m)
if err := dnsco.WriteMsg(m); err != nil {
log.Debugf("Failed to send message: %v", err)
return nil, err
}
readDeadline := time.Now().Add(defaultTimeout)
co.SetReadDeadline(readDeadline)
r, err := dnsco.ReadMsg()
dnsco.Close()
if r == nil {
return nil, err
}
return r, err
return dnsco.ReadMsg()
}