2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-10-10 22:19:50 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
2020-09-17 01:42:06 +00:00
|
|
|
"errors"
|
2020-09-19 01:59:04 +00:00
|
|
|
"fmt"
|
2017-10-10 22:19:50 +00:00
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
2022-02-14 17:45:45 +00:00
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
2017-10-10 22:19:50 +00:00
|
|
|
"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 {
|
2021-05-27 21:29:43 +00:00
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
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-19 01:59:04 +00:00
|
|
|
strings.Contains(errStr, yamuxSessionShutdown) {
|
2017-10-10 22:19:50 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-09-24 19:23:48 +00:00
|
|
|
var serverError rpc.ServerError
|
|
|
|
if errors.As(err, &serverError) {
|
|
|
|
return strings.HasSuffix(err.Error(), fmt.Sprintf(": %s", io.EOF.Error()))
|
2020-09-19 01:59:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 22:19:50 +00:00
|
|
|
return false
|
|
|
|
}
|