mirror of
https://github.com/status-im/consul.git
synced 2025-02-12 21:56:46 +00:00
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)
30 lines
597 B
Go
30 lines
597 B
Go
package lib
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/yamux"
|
|
)
|
|
|
|
var yamuxStreamClosed = yamux.ErrStreamClosed.Error()
|
|
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 errors.Is(err, io.EOF) {
|
|
return true
|
|
}
|
|
|
|
errStr := err.Error()
|
|
if strings.Contains(errStr, yamuxStreamClosed) ||
|
|
strings.Contains(errStr, yamuxSessionShutdown) ||
|
|
strings.HasSuffix(errStr, io.EOF.Error()) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|