From 3f82ab0bbc951ff82e0c8fa92b0c277db9477acc Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Sun, 24 Apr 2022 13:54:30 -0500 Subject: [PATCH] drpcmanager: cancel stream with error when terminated Terminations were canceling streams with `context.Canceled` instead of surfacing the error, causing unexpected behavior. --- drpcmanager/manager.go | 3 ++- internal/integration/transport_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drpcmanager/manager.go b/drpcmanager/manager.go index 5723abe..9eb3812 100644 --- a/drpcmanager/manager.go +++ b/drpcmanager/manager.go @@ -291,7 +291,8 @@ func (m *Manager) manageStream(ctx context.Context, stream *drpcstream.Stream) { select { case <-m.sigs.term.Signal(): - stream.Cancel(context.Canceled) + err, _ := m.sigs.term.Get() + stream.Cancel(err) <-m.sterm return diff --git a/internal/integration/transport_test.go b/internal/integration/transport_test.go index d86675b..e5052c7 100644 --- a/internal/integration/transport_test.go +++ b/internal/integration/transport_test.go @@ -5,6 +5,8 @@ package integration import ( "context" + "errors" + "io" "testing" "github.com/zeebo/assert" @@ -111,6 +113,6 @@ func TestTransport_ErrorCausesCancel(t *testing.T) { assert.NoError(t, cli.DRPCConn().(*drpcconn.Conn).Transport().Close()) // ensure both of the errors we sent are canceled - assert.Equal(t, <-errs, context.Canceled) - assert.Equal(t, <-errs, context.Canceled) + assert.True(t, errors.Is(<-errs, io.ErrClosedPipe)) + assert.True(t, errors.Is(<-errs, io.EOF)) }