diff --git a/tunnel/tcp.go b/tunnel/tcp.go index 569db02..beb8167 100644 --- a/tunnel/tcp.go +++ b/tunnel/tcp.go @@ -79,12 +79,19 @@ func copyBuffer(dst io.Writer, src io.Reader) error { defer pool.Put(buf) _, err := io.CopyBuffer(dst, src, buf) - if ne, ok := err.(net.Error); ok && ne.Timeout() { - return nil /* ignore I/O timeout */ - } else if errors.Is(err, syscall.EPIPE) { - return nil /* ignore broken pipe */ - } else if errors.Is(err, syscall.ECONNRESET) { - return nil /* ignore connection reset by peer */ + if err != nil && !isIgnorable(err) { + return err } - return err + return nil +} + +func isIgnorable(err error) bool { + if ne, ok := err.(net.Error); ok && ne.Timeout() { + return true /* ignore I/O timeout */ + } else if errors.Is(err, syscall.EPIPE) { + return true /* ignore broken pipe */ + } else if errors.Is(err, syscall.ECONNRESET) { + return true /* ignore connection reset by peer */ + } + return false }