Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpcproxy: only return ctx error in chan stream if recvc is empty #7345

Merged
merged 1 commit into from
Feb 21, 2017

Conversation

heyitsanthony
Copy link
Contributor

Since select{} won't prioritize, ctx.Done() can sometimes override
a pending message on recvc. Loop if recvc has messages instead.

Fixes #7340

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@a5cf7fd). Click here to learn what that means.
The diff coverage is 0%.

@@           Coverage Diff            @@
##             master   #7345   +/-   ##
========================================
  Coverage          ?   63.9%           
========================================
  Files             ?     233           
  Lines             ?   20985           
  Branches          ?       0           
========================================
  Hits              ?   13411           
  Misses            ?    6575           
  Partials          ?     999
Impacted Files Coverage Δ
proxy/grpcproxy/chan_stream.go 0% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5cf7fd...96b769e. Read the comment docs.

select {
case msg, ok := <-s.recvc:
if !ok {
s.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense.
Did we just forget to cancel this context before? And now it fixes?

Copy link
Contributor Author

@heyitsanthony heyitsanthony Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That bit is just extra paranoia. The problem is from recvc being buffered and doing:

ch <- x
cancel()

which leads to the select{} here having both <-s.recvc and <-s.ctx.Done() available for reading. Since go won't prioritize selects, it would randomly choose s.ctx.Done over s.recvc and return a context canceled error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it back since it's not relevant to the fix

@gyuho
Copy link
Contributor

gyuho commented Feb 21, 2017

LGTM

Since select{} won't prioritize, ctx.Done() can sometimes override
a pending message on recvc. Loop if recvc has messages instead.

Fixes etcd-io#7340
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants