Fix error handling with server shutdown

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2019-06-13 17:19:47 +00:00
parent f3eb35b158
commit 3afb82bd27
2 changed files with 14 additions and 15 deletions

View File

@ -202,7 +202,7 @@ func (r *receiver) run(ctx context.Context, c *channel) {
if !ok {
// treat all errors that are not an rpc status as terminal.
// all others poison the connection.
r.err = err
r.err = filterCloseErr(err)
return
}
}
@ -328,22 +328,21 @@ func (c *Client) recv(resp *Response, msg *message) error {
//
// This purposely ignores errors with a wrapped cause.
func filterCloseErr(err error) error {
if err == nil {
switch {
case err == nil:
return nil
}
if err == io.EOF {
case err == io.EOF:
return ErrClosed
}
if strings.Contains(err.Error(), "use of closed network connection") {
case errors.Cause(err) == io.EOF:
return ErrClosed
}
// if we have an epipe on a write, we cast to errclosed
if oerr, ok := err.(*net.OpError); ok && oerr.Op == "write" {
if serr, ok := oerr.Err.(*os.SyscallError); ok && serr.Err == syscall.EPIPE {
return ErrClosed
case strings.Contains(err.Error(), "use of closed network connection"):
return ErrClosed
default:
// if we have an epipe on a write, we cast to errclosed
if oerr, ok := err.(*net.OpError); ok && oerr.Op == "write" {
if serr, ok := oerr.Err.(*os.SyscallError); ok && serr.Err == syscall.EPIPE {
return ErrClosed
}
}
}

View File

@ -351,7 +351,7 @@ func TestClientEOF(t *testing.T) {
}
// shutdown the server so the client stops receiving stuff.
if err := server.Shutdown(ctx); err != nil {
if err := server.Close(); err != nil {
t.Fatal(err)
}
if err := <-errs; err != ErrServerClosed {