From 6e416eafd26e6e738df716b21d421d5b59702bb4 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Mon, 21 Oct 2019 11:57:22 +0800 Subject: [PATCH] return ErrClosed if read: connection reset by peer When call server.Close(), server will close all listener and notify flighting-connection to shutdown. Connections are closed asynchronously. In TestClientEOF, client can send request into closing-connection. But the read for reply will return error if the closing-connection is shutdown. In this case, we should filter error for client side about `read: connection reset by peer`. Signed-off-by: Wei Fu --- client.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index bdd1d12..e816941 100644 --- a/client.go +++ b/client.go @@ -338,9 +338,12 @@ func filterCloseErr(err error) error { case strings.Contains(err.Error(), "use of closed network connection"): return ErrClosed default: - // if we have an epipe on a write, we cast to errclosed - if oerr, ok := err.(*net.OpError); ok && oerr.Op == "write" { - if serr, ok := oerr.Err.(*os.SyscallError); ok && serr.Err == syscall.EPIPE { + // if we have an epipe on a write or econnreset on a read , we cast to errclosed + if oerr, ok := err.(*net.OpError); ok && (oerr.Op == "write" || oerr.Op == "read") { + serr, sok := oerr.Err.(*os.SyscallError) + if sok && ((serr.Err == syscall.EPIPE && oerr.Op == "write") || + (serr.Err == syscall.ECONNRESET && oerr.Op == "read")) { + return ErrClosed } }