From 4f16ed3f3abe963e1c6db8545ac10d6cb01fd8f5 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Tue, 17 Jul 2018 11:23:31 +1000 Subject: [PATCH] Convert io.ErrUnexpectedEOF to a codes.Internal-marked status in toRPCErr. This is consistent with how io.ErrUnexpectedEOF is handled in a bunch of other places (e.g. stream.go, server.go), and signals to application-level code that the error is retryable. --- go16.go | 3 +++ go17.go | 3 +++ rpc_util_test.go | 1 + 3 files changed, 7 insertions(+) diff --git a/go16.go b/go16.go index 0e3a029f9666..73eb59fda949 100644 --- a/go16.go +++ b/go16.go @@ -50,6 +50,9 @@ func toRPCErr(err error) error { if err == nil || err == io.EOF { return err } + if err == io.ErrUnexpectedEOF { + return status.Error(codes.Internal, err.Error()) + } if _, ok := status.FromError(err); ok { return err } diff --git a/go17.go b/go17.go index 486dd73fa23d..5f9ab8c4ef2d 100644 --- a/go17.go +++ b/go17.go @@ -51,6 +51,9 @@ func toRPCErr(err error) error { if err == nil || err == io.EOF { return err } + if err == io.ErrUnexpectedEOF { + return status.Error(codes.Internal, err.Error()) + } if _, ok := status.FromError(err); ok { return err } diff --git a/rpc_util_test.go b/rpc_util_test.go index 6fbebdc3ea16..a4ff94583921 100644 --- a/rpc_util_test.go +++ b/rpc_util_test.go @@ -179,6 +179,7 @@ func TestToRPCErr(t *testing.T) { }{ {transport.StreamError{Code: codes.Unknown, Desc: ""}, status.Error(codes.Unknown, "")}, {transport.ErrConnClosing, status.Error(codes.Unavailable, transport.ErrConnClosing.Desc)}, + {io.ErrUnexpectedEOF, status.Error(codes.Internal, io.ErrUnexpectedEOF.Error())}, } { err := toRPCErr(test.errIn) if _, ok := status.FromError(err); !ok {