Skip to content

Commit b3f2522

Browse files
committed
fix: call is not necessarily closed when dataClosed is true
Signed-off-by: Christian Stewart <[email protected]>
1 parent c0e8279 commit b3f2522

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

srpc/common-rpc.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,26 @@ func (c *commonRPC) Context() context.Context {
4545
// Wait waits for the RPC to finish (remote end closed the stream).
4646
func (c *commonRPC) Wait(ctx context.Context) error {
4747
for {
48-
var dataClosed bool
4948
var err error
5049
var waitCh <-chan struct{}
50+
var rpcCtx context.Context
5151
c.bcast.HoldLock(func(broadcast func(), getWaitCh func() <-chan struct{}) {
52-
dataClosed, err = c.dataClosed, c.remoteErr
52+
rpcCtx, err = c.ctx, c.remoteErr
5353
waitCh = getWaitCh()
5454
})
5555

56-
if dataClosed {
56+
if err != nil {
5757
return err
5858
}
59+
if rpcCtx.Err() != nil {
60+
// rpc must have ended w/o an error being set
61+
return context.Canceled
62+
}
5963

6064
select {
6165
case <-ctx.Done():
6266
return context.Canceled
67+
case <-rpcCtx.Done():
6368
case <-waitCh:
6469
}
6570
}

0 commit comments

Comments
 (0)