From 66e680a56f3e0e29a17d592c6b94b807ecffe44a Mon Sep 17 00:00:00 2001 From: Tomer Froumin Date: Tue, 29 Sep 2020 10:50:22 +0300 Subject: [PATCH] Fixed check of syscall errors --- http_client.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/http_client.go b/http_client.go index 548140a..92c6065 100644 --- a/http_client.go +++ b/http_client.go @@ -11,6 +11,7 @@ import ( "net/http" "net/http/httputil" "net/url" + "os" "runtime/debug" "strconv" "strings" @@ -183,18 +184,26 @@ func (c *HTTPClient) Disconnect() { } } +func isSyscallOpError(err error, errno syscall.Errno) bool { + if opErr, ok := err.(*net.OpError); ok { + if syscallErr, ok := opErr.Err.(*os.SyscallError); ok { + return syscallErr.Err == errno + } + } + return err == errno +} + func (c *HTTPClient) isAlive(readBytes *int) bool { // Ready 1 byte from socket without timeout to check if it not closed c.conn.SetReadDeadline(time.Now().Add(time.Millisecond)) n, err := c.conn.Read(c.respBuf[:1]) - if err == io.EOF { + if err == io.EOF || isSyscallOpError(err, syscall.ECONNRESET) { Debug(3, "[HTTPClient] connection closed, reconnecting") return false } - - if err == syscall.EPIPE { - Debug(3, "Detected broken pipe.", err) + if isSyscallOpError(err, syscall.EPIPE) { + Debug(3, "[HTTPClient] Detected broken pipe.", err) return false } if n != 0 {