-
-
Couldn't load subscription status.
- Fork 2.8k
fix: return RecvError if channel is closed when calling watch::Receiver::changed
#7556
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
fix: return RecvError if channel is closed when calling watch::Receiver::changed
#7556
Conversation
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'm considering which behavior should be chosen.
Apparently, we should align the behavior of both has_changed and changed. Otherwise, inconsistent behavior will confuse downstream users. Now, we have two options when there is no active Sender.
Don't return RecvError until the latest value is marked as seen
This means:
has_changedkeeps returningOk(true)until other methods (likechangedormark_changed) are called. After that, subsequent calls returnRecvError.- The first call to
changedreturnsOk(()), and subsequent calls returnRecvError.
In this design, when there is no active sender, the downstream does not lose the last value. However, unless the downstream manually marks the value as seen (via changed or mark_changed), it cannot detect that the sender is no longer active.
Return RecvError regardless of whether a new value exists
This means:
has_changedkeeps returningRecvErroreven when a new value is available.changedalso keeps returningRecvErroreven when a new value is available.
In this design, when there is no active sender, the downstream may lose the last value. However, it can immediately detect that there is no active sender.
I prefer the first option because:
- It is unlikely for downstream to keep calling
has_changedand no other code paths mark the value as seen. - My personal guess is that some downstream might be relying on the behavior that
changeddoes not lose its last value.
Could you share your thoughts?
|
Thanks @ADD-SP for posting your thoughts! Indeed, we should definitely align the behavior of both methods 1. Don't return
|
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 can't understand and distinguish these interfaces in a few minutes.
|
Closing this PR. Thinking more over it, your suggestion of instead changing the behavior of Will reopen a new PR for it shortly. |
Motivation
Solves #7281 . The specification of watch::Receiver::changed says,
A regression test has been added,
changed_errors_on_closed_channel, to verify that the proposed changes fixes the implementation ofchangedto conform to he specification.Solution
The PR fixes the bug in
changedby adding an early check inchanged_implon whether the channel is closed before checking if the value is changed.