diff options
author | Valery Piashchynski <[email protected]> | 2020-08-27 22:34:41 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-08-27 22:34:41 +0300 |
commit | 50d12dcb0649836db1ac8670720fa0112c430b1e (patch) | |
tree | 20ea0240aae418f399b1df3a35bf993528ca5d68 /service | |
parent | a7f8371096fce063d64d0ea3e780685a366c537b (diff) |
handle aborted connection on windows
Diffstat (limited to 'service')
-rw-r--r-- | service/http/response.go | 24 | ||||
-rw-r--r-- | service/http/response_windows.go | 24 |
2 files changed, 39 insertions, 9 deletions
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 +} |