From a940703ae1c290b47d357e0fceef82a6e1c74f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 25 Aug 2022 10:56:57 +0800 Subject: [PATCH] Suppress expected error --- inbound/naive.go | 3 +++ transport/v2raygrpc/conn.go | 3 +++ transport/v2rayhttp/conn.go | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/inbound/naive.go b/inbound/naive.go index cd4591cc..b082d5a9 100644 --- a/inbound/naive.go +++ b/inbound/naive.go @@ -603,5 +603,8 @@ func wrapHttpError(err error) error { if strings.Contains(err.Error(), "body closed by handler") { return net.ErrClosed } + if strings.Contains(err.Error(), "canceled with error code 268") { + return io.EOF + } return err } diff --git a/transport/v2raygrpc/conn.go b/transport/v2raygrpc/conn.go index 295c05b4..34281706 100644 --- a/transport/v2raygrpc/conn.go +++ b/transport/v2raygrpc/conn.go @@ -102,5 +102,8 @@ func wrapError(err error) error { if strings.Contains(err.Error(), "EOF") { return io.EOF } + if strings.Contains(err.Error(), "the client connection is closing") { + return net.ErrClosed + } return err } diff --git a/transport/v2rayhttp/conn.go b/transport/v2rayhttp/conn.go index 61d2ad01..22f3ca4a 100644 --- a/transport/v2rayhttp/conn.go +++ b/transport/v2rayhttp/conn.go @@ -8,6 +8,7 @@ import ( "time" "github.com/sagernet/sing/common" + E "github.com/sagernet/sing/common/exceptions" ) type HTTPConn struct { @@ -16,11 +17,13 @@ type HTTPConn struct { } func (c *HTTPConn) Read(b []byte) (n int, err error) { - return c.reader.Read(b) + n, err = c.reader.Read(b) + return n, wrapError(err) } func (c *HTTPConn) Write(b []byte) (n int, err error) { - return c.writer.Write(b) + n, err = c.writer.Write(b) + return n, wrapError(err) } func (c *HTTPConn) Close() error { @@ -59,3 +62,10 @@ func (c *ServerHTTPConn) Write(b []byte) (n int, err error) { } return } + +func wrapError(err error) error { + if E.IsMulti(err, io.ErrUnexpectedEOF) { + return io.EOF + } + return err +}