-
Notifications
You must be signed in to change notification settings - Fork 248
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
LightClient: Unsubscribe from subscriptions #1408
Conversation
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
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.
LGTM, nice work! 👍
} | ||
} else { | ||
// User dropped the receiver, unsubscribe from the method and remove internal tracking. | ||
let Some(subscription_state) = self.subscriptions.remove(&(id, chain_id)) else { |
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'd have to check; is the only kind of error that can be returned from the channel above one that indicates it was closed by the receiver?
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.
Yep, taken from https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.UnboundedSender.html#method.send:
If the receive half of the channel is closed, either due to close being called or the UnboundedReceiver having been dropped, this function returns an error. The error includes the value passed to send.
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.
Looks good to me; good job spotting and fixing this!
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Previous to the PR, subscribing to a method would never call unsubscribe from that method, even when the user dropped the subscription.
This PR ensures that the appropriate
unsubscribe
method is being called to avoid consuming unnecessary memory, overloading the smoldot instance by never-ending subscriptions, and unwanted side-effects as imposing a maximum limit of subscriptions after which they are rejected.To achieve this:
Running the subxt test suite for the light-client produced multiple warnings;
With this PR, the smoldot acknowledges the unsubscribe method and stops the subscription:
Closes: #1402