2017-10-10 22:19:50 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
2020-09-17 01:42:06 +00:00
|
|
|
"errors"
|
2017-10-10 22:19:50 +00:00
|
|
|
"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 {
|
2020-09-17 01:42:06 +00:00
|
|
|
if errors.Is(err, io.EOF) {
|
2017-10-10 22:19:50 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
errStr := err.Error()
|
|
|
|
if strings.Contains(errStr, yamuxStreamClosed) ||
|
2020-09-17 01:42:06 +00:00
|
|
|
strings.Contains(errStr, yamuxSessionShutdown) ||
|
|
|
|
strings.HasSuffix(errStr, io.EOF.Error()) {
|
2017-10-10 22:19:50 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|