From: Matt Joiner Date: Sat, 13 Sep 2014 17:45:38 +0000 (+1000) Subject: Treat ECONNRESET and i/o timeout from peers as EOF X-Git-Tag: v1.0.0~1565 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7fccb77ebe12d2180ab147b7e1325ef95f8532c9;p=btrtrc.git Treat ECONNRESET and i/o timeout from peers as EOF --- diff --git a/client.go b/client.go index 50f2136b..72782463 100644 --- a/client.go +++ b/client.go @@ -492,6 +492,16 @@ func (pc peerConn) Read(b []byte) (n int, err error) { return } n, err = pc.Conn.Read(b) + if err != nil { + if opError, ok := err.(*net.OpError); ok && opError.Op == "read" && opError.Err == syscall.ECONNRESET { + err = io.EOF + } else if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + if n != 0 { + panic(n) + } + err = io.EOF + } + } return }