Make IsConnectionReset work with more error implementations.

This commit is contained in:
Marcin Owsiany 2018-01-19 14:16:47 +01:00
parent a8a418b0ae
commit 313128d760

View File

@ -18,6 +18,8 @@ package net
import ( import (
"net" "net"
"net/url"
"os"
"reflect" "reflect"
"syscall" "syscall"
) )
@ -38,8 +40,16 @@ func IPNetEqual(ipnet1, ipnet2 *net.IPNet) bool {
// Returns if the given err is "connection reset by peer" error. // Returns if the given err is "connection reset by peer" error.
func IsConnectionReset(err error) bool { func IsConnectionReset(err error) bool {
opErr, ok := err.(*net.OpError) if urlErr, ok := err.(*url.Error); ok {
if ok && opErr.Err.Error() == syscall.ECONNRESET.Error() { err = urlErr.Err
}
if opErr, ok := err.(*net.OpError); ok {
err = opErr.Err
}
if osErr, ok := err.(*os.SyscallError); ok {
err = osErr.Err
}
if errno, ok := err.(syscall.Errno); ok && errno == syscall.ECONNRESET {
return true return true
} }
return false return false