diff --git a/client.go b/client.go index 9068be1793..2eaab39d4e 100644 --- a/client.go +++ b/client.go @@ -13,7 +13,6 @@ import ( "strings" "sync" "sync/atomic" - "syscall" "time" ) @@ -1439,8 +1438,8 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error) err = bw.Flush() } c.releaseWriter(bw) - isECONNRESET := errors.Is(err, syscall.ECONNRESET) - if err != nil && !isECONNRESET { + isConnRST := isConnectionReset(err) + if err != nil && !isConnRST { c.closeConn(cc) return true, err } @@ -1472,7 +1471,7 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error) return retry, err } - if resetConnection || req.ConnectionClose() || resp.ConnectionClose() || isECONNRESET { + if resetConnection || req.ConnectionClose() || resp.ConnectionClose() || isConnRST { c.closeConn(cc) } else { c.releaseConn(cc) diff --git a/client_test.go b/client_test.go index 62c5546dce..b5725ad667 100644 --- a/client_test.go +++ b/client_test.go @@ -4,7 +4,6 @@ import ( "bufio" "bytes" "crypto/tls" - "errors" "fmt" "io" "io/ioutil" @@ -17,7 +16,6 @@ import ( "strings" "sync" "sync/atomic" - "syscall" "testing" "time" @@ -2955,7 +2953,7 @@ func TestRstConnClosedWithoutResponse(t *testing.T) { err = client.Do(req, resp) - if !errors.Is(err, syscall.ECONNRESET) { + if !isConnectionReset(err) { t.Fatalf("Expected connection reset error") } } diff --git a/http.go b/http.go index aede0c6aec..75b40c9b74 100644 --- a/http.go +++ b/http.go @@ -12,7 +12,6 @@ import ( "net" "os" "sync" - "syscall" "time" "github.com/valyala/bytebufferpool" @@ -1292,7 +1291,7 @@ func (resp *Response) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { if !resp.mustSkipBody() { err = resp.ReadBody(r, maxBodySize) if err != nil { - if errors.Is(err, syscall.ECONNRESET) { + if isConnectionReset(err) { return nil } return err @@ -1302,7 +1301,7 @@ func (resp *Response) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { if resp.Header.ContentLength() == -1 { err = resp.Header.ReadTrailer(r) if err != nil && err != io.EOF { - if errors.Is(err, syscall.ECONNRESET) { + if isConnectionReset(err) { return nil } return err diff --git a/tcp.go b/tcp.go new file mode 100644 index 0000000000..54d30334ea --- /dev/null +++ b/tcp.go @@ -0,0 +1,13 @@ +//go:build !windows +// +build !windows + +package fasthttp + +import ( + "errors" + "syscall" +) + +func isConnectionReset(err error) bool { + return errors.Is(err, syscall.ECONNRESET) +} diff --git a/tcp_windows.go b/tcp_windows.go new file mode 100644 index 0000000000..5c33025f40 --- /dev/null +++ b/tcp_windows.go @@ -0,0 +1,13 @@ +//go:build windows +// +build windows + +package fasthttp + +import ( + "errors" + "syscall" +) + +func isConnectionReset(err error) bool { + return errors.Is(err, syscall.WSAECONNRESET) +}