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
fe984b3ee3
commit
b35874e1a6
|
@ -1,6 +1,7 @@
|
||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -13,13 +14,14 @@ var yamuxSessionShutdown = yamux.ErrSessionShutdown.Error()
|
||||||
// IsErrEOF returns true if we get an EOF error from the socket itself, or
|
// IsErrEOF returns true if we get an EOF error from the socket itself, or
|
||||||
// an EOF equivalent error from yamux.
|
// an EOF equivalent error from yamux.
|
||||||
func IsErrEOF(err error) bool {
|
func IsErrEOF(err error) bool {
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
errStr := err.Error()
|
errStr := err.Error()
|
||||||
if strings.Contains(errStr, yamuxStreamClosed) ||
|
if strings.Contains(errStr, yamuxStreamClosed) ||
|
||||||
strings.Contains(errStr, yamuxSessionShutdown) {
|
strings.Contains(errStr, yamuxSessionShutdown) ||
|
||||||
|
strings.HasSuffix(errStr, io.EOF.Error()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue