mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 18:35:11 -05:00
plugin/forward: retry on cached tcp connection closed by peer (#1655)
* plugin/forward: retry on cached tcp connection closed by peer * fix linter warnings * fixed unit test * modify error message
This commit is contained in:
committed by
Miek Gieben
parent
848a5d7c79
commit
e46ee9d9cc
@@ -5,6 +5,7 @@
|
||||
package forward
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -22,7 +23,7 @@ func (p *Proxy) connect(ctx context.Context, state request.Request, forceTCP, me
|
||||
proto = "tcp"
|
||||
}
|
||||
|
||||
conn, err := p.Dial(proto)
|
||||
conn, cached, err := p.Dial(proto)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -36,6 +37,9 @@ func (p *Proxy) connect(ctx context.Context, state request.Request, forceTCP, me
|
||||
conn.SetWriteDeadline(time.Now().Add(timeout))
|
||||
if err := conn.WriteMsg(state.Req); err != nil {
|
||||
conn.Close() // not giving it back
|
||||
if err == io.EOF && cached {
|
||||
return nil, errCachedClosed
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -43,6 +47,9 @@ func (p *Proxy) connect(ctx context.Context, state request.Request, forceTCP, me
|
||||
ret, err := conn.ReadMsg()
|
||||
if err != nil {
|
||||
conn.Close() // not giving it back
|
||||
if err == io.EOF && cached {
|
||||
return nil, errCachedClosed
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user