mirror of https://github.com/status-im/consul.git
Use errors.Is() in IsErrEOF()
IsErrEOF returns false when it should return true in a couple of cases: 1. if the error has been wrapped in another error (for example, if EOF is wrapped in an RPC error) 2. if the error has been created from an Error field in an RPC response (as it is the case in CallWithCodec in the net-rpc-msgpackrpc package for example)
This commit is contained in:
parent
6b62751921
commit
012f31fc2d
|
@ -1,6 +1,7 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
|
@ -13,13 +14,14 @@ var yamuxSessionShutdown = yamux.ErrSessionShutdown.Error()
|
|||
// IsErrEOF returns true if we get an EOF error from the socket itself, or
|
||||
// an EOF equivalent error from yamux.
|
||||
func IsErrEOF(err error) bool {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return true
|
||||
}
|
||||
|
||||
errStr := err.Error()
|
||||
if strings.Contains(errStr, yamuxStreamClosed) ||
|
||||
strings.Contains(errStr, yamuxSessionShutdown) {
|
||||
strings.Contains(errStr, yamuxSessionShutdown) ||
|
||||
strings.HasSuffix(errStr, io.EOF.Error()) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue