Fix isTimeout

This commit is contained in:
世界 2022-04-27 12:53:03 +08:00
parent 82e1dc7058
commit 0a8e8d675f
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net"
"os"
"syscall"
)
@ -60,8 +61,13 @@ func IsTimeout(err error) bool {
if unwrapErr := errors.Unwrap(err); unwrapErr != nil {
err = unwrapErr
}
if opErr, isOpErr := err.(*net.OpError); isOpErr {
return opErr.Timeout()
if ne, ok := err.(*os.SyscallError); ok {
err = ne.Err
}
if timeoutErr, isTimeoutErr := err.(interface {
Timeout() bool
}); isTimeoutErr {
return timeoutErr.Timeout()
}
return false
}