grpcproxy: only return ctx error in chan stream if recvc is empty
Since select{} won't prioritize, ctx.Done() can sometimes override
a pending message on recvc. Loop if recvc has messages instead.
Fixes
@@ -116,6 +116,7 @@ func (s *chanStream) SendMsg(m interface{}) error {
func (s *chanStream) RecvMsg(m interface{}) error {
v := m.(*interface{})
+ for {
select {
case msg, ok := <-s.recvc:
if !ok {
@@ -128,5 +129,10 @@ func (s *chanStream) RecvMsg(m interface{}) error {
return nil
case <-s.ctx.Done():
}
+ if len(s.recvc) == 0 {
+ // prioritize any pending recv messages over canceled context
+ break
+ }
+ }
return s.ctx.Err()
}
