aboutsummaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/grpc/rpc_util.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/grpc/rpc_util.go')
-rw-r--r--vendor/google.golang.org/grpc/rpc_util.go56
1 files changed, 45 insertions, 11 deletions
diff --git a/vendor/google.golang.org/grpc/rpc_util.go b/vendor/google.golang.org/grpc/rpc_util.go
index 06544ad..d628717 100644
--- a/vendor/google.golang.org/grpc/rpc_util.go
+++ b/vendor/google.golang.org/grpc/rpc_util.go
@@ -61,7 +61,7 @@ type Codec interface {
String() string
}
-// protoCodec is a Codec implemetation with protobuf. It is the default codec for gRPC.
+// protoCodec is a Codec implementation with protobuf. It is the default codec for gRPC.
type protoCodec struct{}
func (protoCodec) Marshal(v interface{}) ([]byte, error) {
@@ -141,6 +141,8 @@ type callInfo struct {
traceInfo traceInfo // in trace.go
}
+var defaultCallInfo = callInfo{failFast: true}
+
// CallOption configures a Call before it starts or extracts information from
// a Call after it completes.
type CallOption interface {
@@ -179,6 +181,19 @@ func Trailer(md *metadata.MD) CallOption {
})
}
+// FailFast configures the action to take when an RPC is attempted on broken
+// connections or unreachable servers. If failfast is true, the RPC will fail
+// immediately. Otherwise, the RPC client will block the call until a
+// connection is available (or the call is canceled or times out) and will retry
+// the call if it fails due to a transient error. Please refer to
+// https://github.com/grpc/grpc/blob/master/doc/fail_fast.md
+func FailFast(failFast bool) CallOption {
+ return beforeCall(func(c *callInfo) error {
+ c.failFast = failFast
+ return nil
+ })
+}
+
// The format of the payload: compressed or not?
type payloadFormat uint8
@@ -187,7 +202,7 @@ const (
compressionMade
)
-// parser reads complelete gRPC messages from the underlying reader.
+// parser reads complete gRPC messages from the underlying reader.
type parser struct {
// r is the underlying reader.
// See the comment on recvMsg for the permissible
@@ -319,7 +334,7 @@ type rpcError struct {
desc string
}
-func (e rpcError) Error() string {
+func (e *rpcError) Error() string {
return fmt.Sprintf("rpc error: code = %d desc = %s", e.code, e.desc)
}
@@ -329,7 +344,7 @@ func Code(err error) codes.Code {
if err == nil {
return codes.OK
}
- if e, ok := err.(rpcError); ok {
+ if e, ok := err.(*rpcError); ok {
return e.code
}
return codes.Unknown
@@ -341,7 +356,7 @@ func ErrorDesc(err error) string {
if err == nil {
return ""
}
- if e, ok := err.(rpcError); ok {
+ if e, ok := err.(*rpcError); ok {
return e.desc
}
return err.Error()
@@ -353,7 +368,7 @@ func Errorf(c codes.Code, format string, a ...interface{}) error {
if c == codes.OK {
return nil
}
- return rpcError{
+ return &rpcError{
code: c,
desc: fmt.Sprintf(format, a...),
}
@@ -362,18 +377,37 @@ func Errorf(c codes.Code, format string, a ...interface{}) error {
// toRPCErr converts an error into a rpcError.
func toRPCErr(err error) error {
switch e := err.(type) {
- case rpcError:
+ case *rpcError:
return err
case transport.StreamError:
- return rpcError{
+ return &rpcError{
code: e.Code,
desc: e.Desc,
}
case transport.ConnectionError:
- return rpcError{
+ return &rpcError{
code: codes.Internal,
desc: e.Desc,
}
+ default:
+ switch err {
+ case context.DeadlineExceeded:
+ return &rpcError{
+ code: codes.DeadlineExceeded,
+ desc: err.Error(),
+ }
+ case context.Canceled:
+ return &rpcError{
+ code: codes.Canceled,
+ desc: err.Error(),
+ }
+ case ErrClientConnClosing:
+ return &rpcError{
+ code: codes.FailedPrecondition,
+ desc: err.Error(),
+ }
+ }
+
}
return Errorf(codes.Unknown, "%v", err)
}
@@ -406,10 +440,10 @@ func convertCode(err error) codes.Code {
return codes.Unknown
}
-// SupportPackageIsVersion2 is referenced from generated protocol buffer files
+// SupportPackageIsVersion3 is referenced from generated protocol buffer files
// to assert that that code is compatible with this version of the grpc package.
//
// This constant may be renamed in the future if a change in the generated code
// requires a synchronised update of grpc-go and protoc-gen-go. This constant
// should not be referenced from any other code.
-const SupportPackageIsVersion2 = true
+const SupportPackageIsVersion3 = true