From 50d12dcb0649836db1ac8670720fa0112c430b1e Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 27 Aug 2020 22:34:41 +0300 Subject: handle aborted connection on windows --- service/http/response.go | 24 +++++++++++++++--------- service/http/response_windows.go | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 service/http/response_windows.go diff --git a/service/http/response.go b/service/http/response.go index 045f56da..ebb90994 100644 --- a/service/http/response.go +++ b/service/http/response.go @@ -1,3 +1,5 @@ +// +build !windows + package http import ( @@ -14,7 +16,7 @@ import ( "github.com/spiral/roadrunner" ) -var errEPIPE = errors.New("EPIPE(32) -> possibly connection reset by peer") +var errEPIPE = errors.New("EPIPE(32) -> connection reset by peer") // Response handles PSR7 response logic. type Response struct { @@ -64,14 +66,7 @@ func (r *Response) Write(w http.ResponseWriter) error { if data, ok := r.body.([]byte); ok { _, err := w.Write(data) if err != nil { - if netErr, ok2 := err.(*net.OpError); ok2 { - if syscallErr, ok3 := netErr.Err.(*os.SyscallError); ok3 { - if syscallErr.Err == syscall.EPIPE { - return errEPIPE - } - } - } - return err + return handleWriteError(err) } } @@ -84,6 +79,17 @@ func (r *Response) Write(w http.ResponseWriter) error { return nil } +func handleWriteError(err error) error { + if netErr, ok2 := err.(*net.OpError); ok2 { + if syscallErr, ok3 := netErr.Err.(*os.SyscallError); ok3 { + if syscallErr.Err == syscall.EPIPE { + return errEPIPE + } + } + } + return err +} + func handlePushHeaders(h map[string][]string) []string { var p []string pushHeader, ok := h[http2pushHeaderKey] diff --git a/service/http/response_windows.go b/service/http/response_windows.go new file mode 100644 index 00000000..f1ac6a37 --- /dev/null +++ b/service/http/response_windows.go @@ -0,0 +1,24 @@ +// +build windows + +package http + +import ( + "errors" + "net" + "os" + "syscall" +) + +var errEPIPE = errors.New("WSAECONNABORTED (10053) -> an established connection was aborted") + +// handleWriteError just check if error was caused by aborted connection +func handleWriteError(err error) error { + if netErr, ok2 := err.(*net.OpError); ok2 { + if syscallErr, ok3 := netErr.Err.(*os.SyscallError); ok3 { + if syscallErr.Err == syscall.WSAECONNABORTED { + return errEPIPE + } + } + } + return err +} -- cgit v1.2.3