starpc 0.37.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.37.0",
3
+ "version": "0.37.1",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -45,21 +45,26 @@ func (c *commonRPC) Context() context.Context {
45
45
  // Wait waits for the RPC to finish (remote end closed the stream).
46
46
  func (c *commonRPC) Wait(ctx context.Context) error {
47
47
  for {
48
- var dataClosed bool
49
48
  var err error
50
49
  var waitCh <-chan struct{}
50
+ var rpcCtx context.Context
51
51
  c.bcast.HoldLock(func(broadcast func(), getWaitCh func() <-chan struct{}) {
52
- dataClosed, err = c.dataClosed, c.remoteErr
52
+ rpcCtx, err = c.ctx, c.remoteErr
53
53
  waitCh = getWaitCh()
54
54
  })
55
55
 
56
- if dataClosed {
56
+ if err != nil {
57
57
  return err
58
58
  }
59
+ if rpcCtx.Err() != nil {
60
+ // rpc must have ended w/o an error being set
61
+ return context.Canceled
62
+ }
59
63
 
60
64
  select {
61
65
  case <-ctx.Done():
62
66
  return context.Canceled
67
+ case <-rpcCtx.Done():
63
68
  case <-waitCh:
64
69
  }
65
70
  }
@@ -94,6 +94,7 @@ func CheckServerStream(t *testing.T, out echo.SRPCEchoer_EchoServerStreamClient,
94
94
  }
95
95
  return err
96
96
  }
97
+
97
98
  body := echoMsg.GetBody()
98
99
  bodyTxt := req.GetBody()
99
100
  if body != bodyTxt {
@@ -101,10 +102,17 @@ func CheckServerStream(t *testing.T, out echo.SRPCEchoer_EchoServerStreamClient,
101
102
  }
102
103
  t.Logf("server->client message %d/%d", totalExpected-expectedRx+1, totalExpected)
103
104
  expectedRx--
105
+
106
+ if out.Context().Err() != nil {
107
+ return errors.New("expected context not canceled yet")
108
+ }
104
109
  }
105
110
  if expectedRx < 0 {
106
111
  return errors.Errorf("got %d more messages than expected", -1*expectedRx)
107
112
  }
113
+ if expectedRx > 0 {
114
+ return errors.Errorf("got %d less messages than expected", expectedRx)
115
+ }
108
116
  return nil
109
117
  }
110
118