From 36837c1da29974547316a2735e617f342b22ca2a Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 8 Oct 2020 14:39:30 +0300 Subject: [PATCH] Try to fix test on windows --- lib/netext/httpext/error_codes.go | 6 +++++- lib/netext/httpext/error_codes_syscall_posix.go | 12 ++++++++++++ .../httpext/error_codes_syscall_windows.go | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/netext/httpext/error_codes_syscall_posix.go create mode 100644 lib/netext/httpext/error_codes_syscall_windows.go diff --git a/lib/netext/httpext/error_codes.go b/lib/netext/httpext/error_codes.go index 4663c95943a..f55cfb60d8a 100644 --- a/lib/netext/httpext/error_codes.go +++ b/lib/netext/httpext/error_codes.go @@ -145,12 +145,16 @@ func errorCodeForError(err error) (errCode, string) { return defaultNetNonTCPErrorCode, err.Error() } if sErr, ok := e.Err.(*os.SyscallError); ok { - switch sErr.Err { + switch sErr.Unwrap() { case syscall.ECONNRESET: return tcpResetByPeerErrorCode, fmt.Sprintf(tcpResetByPeerErrorCodeMsg, e.Op) case syscall.EPIPE: return tcpBrokenPipeErrorCode, fmt.Sprintf(tcpBrokenPipeErrorCodeMsg, e.Op) } + code, msg := getOSSyscallErrorCode(e, sErr) + if code != 0 { + return code, msg + } } if e.Op == "dial" { if e.Timeout() { diff --git a/lib/netext/httpext/error_codes_syscall_posix.go b/lib/netext/httpext/error_codes_syscall_posix.go new file mode 100644 index 00000000000..65a61a924c6 --- /dev/null +++ b/lib/netext/httpext/error_codes_syscall_posix.go @@ -0,0 +1,12 @@ +// +build !windows + +package httpext + +import ( + "net" + "os" +) + +func getOSSyscallErrorCode(e *net.OpError, se *os.SyscallError) (errCode, string) { + return 0, "" +} diff --git a/lib/netext/httpext/error_codes_syscall_windows.go b/lib/netext/httpext/error_codes_syscall_windows.go new file mode 100644 index 00000000000..27e82e342f1 --- /dev/null +++ b/lib/netext/httpext/error_codes_syscall_windows.go @@ -0,0 +1,16 @@ +package httpext + +import ( + "fmt" + "net" + "os" + "syscall" +) + +func getOSSyscallErrorCode(e *net.OpError, se *os.SyscallError) (errCode, string) { + switch se.Unwrap() { + case syscall.WSAECONNRESET: + return tcpResetByPeerErrorCode, fmt.Sprintf(tcpResetByPeerErrorCodeMsg, e.Op) + } + return 0, "" +}