-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
clientV3watch: do not return ctx canceled when Close watch #10420
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10420 +/- ##
==========================================
+ Coverage 71.4% 71.59% +0.19%
==========================================
Files 393 393
Lines 36503 36505 +2
==========================================
+ Hits 26064 26135 +71
+ Misses 8604 8545 -59
+ Partials 1835 1825 -10
Continue to review full report at Codecov.
|
@@ -371,6 +371,9 @@ func (w *watcher) Close() (err error) { | |||
err = werr | |||
} | |||
} | |||
if err == context.Canceled { | |||
return fmt.Errorf("Context canceled as expected") | |||
} | |||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there situations where context would be canceled here but not expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's the case right now that it's canceled but not expected by end user. https://github.com/etcd-io/etcd/blob/master/clientv3/watch.go#L414
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand I just mean are there possible corner cases in your experience where this error message would not be appropriate. I am only asking because I have not dug into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hexfusion So far playing with it, I believe this message covers both cases - one where it's displayed without user being explicitly canceling it (i.e. by calling Close which seems most common case) and second if there is anyway context was canceled by user (I wonder why anyone would do this but just thinking as a possible case).
@spzala thanks for the PR! Can you please rebase with master? |
@hexfusion thanks, rebased! |
@gyuho PTAL this seems fine to me but maybe you have ideas on corner cases? |
I think |
|
clientv3/watch.go
Outdated
@@ -371,6 +371,9 @@ func (w *watcher) Close() (err error) { | |||
err = werr | |||
} | |||
} | |||
if err == context.Canceled { | |||
return fmt.Errorf("Context canceled as expected") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should return nil here as context cancel is expected with a related message as here, so that end user see call to the Close() as success instead of one returned with error. Just a thought as we are discussing the PR. Thanks!
If watcher.Close() closes the watcher as expected, shouldn't it return no error? |
A gentle reminder for review :-) As @jingyih and I commented earlier, we should probably return no error. @hexfusion @gyuho |
@spzala While I agree with you, we should not introduce a new error value. User would need to handle another error string
So long as we document clearly, we should just keep the old behavior. I would rather update the godoc here https://github.com/etcd-io/etcd/blob/master/clientv3/watch.go#L45. |
@gyuho thanks and agree! I was leaning towards not throwing error at all, but updating doc sounds good too, will update PR accordingly. |
@gyuho @hexfusion does the doc clarification look good? Thanks! |
If the user calls Close directly (instead of closing the context, then call Close), Close should not return an error. |
Closing of watch by client will cancel the watch grpc stream and can produce a context canceled error. However, since client simply wanted to close the watcher the error can create confusion that something went wrong instead of a successful close. Ensure that Close do not return error. Fixed etcd-io#10340
lgtm |
Thanks @xiang90 !! |
Thanks for fixing this:) |
Closing of watch by client will cancel the watch grpc stream and
can produce a context canceled error. However, since client
simply wanted to close the watcher the error can create confusion
that something went wrong instead of a successful close. Ensure
that Close do not return ctx canceled error.
Fixed #10340