Skip to content

Commit

Permalink
Merge pull request #7345 from heyitsanthony/fix-stream-err
Browse files Browse the repository at this point in the history
grpcproxy: only return ctx error in chan stream if recvc is empty
  • Loading branch information
Anthony Romano committed Feb 21, 2017
2 parents 86cb9f2 + 29a6fd6 commit 3c20bdd
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions proxy/grpcproxy/chan_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,23 @@ func (s *chanStream) SendMsg(m interface{}) error {

func (s *chanStream) RecvMsg(m interface{}) error {
v := m.(*interface{})
select {
case msg, ok := <-s.recvc:
if !ok {
return grpc.ErrClientConnClosing
for {
select {
case msg, ok := <-s.recvc:
if !ok {
return grpc.ErrClientConnClosing
}
if err, ok := msg.(error); ok {
return err
}
*v = msg
return nil
case <-s.ctx.Done():
}
if err, ok := msg.(error); ok {
return err
if len(s.recvc) == 0 {
// prioritize any pending recv messages over canceled context
break
}
*v = msg
return nil
case <-s.ctx.Done():
}
return s.ctx.Err()
}

0 comments on commit 3c20bdd

Please sign in to comment.