Skip to content

Commit

Permalink
drpcmanager: cancel stream with error when terminated
Browse files Browse the repository at this point in the history
Terminations were canceling streams with `context.Canceled` instead
of surfacing the error, causing unexpected behavior.
  • Loading branch information
kylecarbs committed Apr 24, 2022
1 parent 41e8fa5 commit 3f82ab0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion drpcmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions internal/integration/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package integration

import (
"context"
"errors"
"io"
"testing"

"github.com/zeebo/assert"
Expand Down Expand Up @@ -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))
}

0 comments on commit 3f82ab0

Please sign in to comment.