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

Replace async-channel #708

Merged
merged 23 commits into from
Mar 9, 2022
Merged

Replace async-channel #708

merged 23 commits into from
Mar 9, 2022

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Feb 22, 2022

Replace async-channel with tokio::sync::Notify to use a dependency less and (possibly?) be a bit faster by using a lighter primitive (maybe?). The problem the async-channel is solving is: how does the SubscriptionSink know about rude subscribers that leaves without calling unsubscribe_*? Using a full-on channel for this might be overkill and this is an attempt at fixing that.

Fixes #691

Use tokio::sync::Notify to signal to the server when a subscriber has gone away without calling unsubscribe
@dvdplm dvdplm self-assigned this Feb 22, 2022
ws-server/src/server.rs Outdated Show resolved Hide resolved
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
dvdplm and others added 4 commits February 23, 2022 10:08
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
ws-server/src/server.rs Outdated Show resolved Hide resolved
Add a second subscription to serverless test
@dvdplm dvdplm marked this pull request as ready for review February 24, 2022 09:33
@dvdplm dvdplm requested a review from a team as a code owner February 24, 2022 09:33
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

LGTM

core/src/server/rpc_module.rs Outdated Show resolved Hide resolved
Either::Right((None, _)) => {
self.close(&SubscriptionClosed::new(SubscriptionClosedReason::ConnectionReset));
break Ok(());
if let Some(close_notify) = self.close_notify.clone() {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need the clone here @dvdplm?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't move out the Arc<Notify> and I can't use a reference either (because send takes a mutable reference below). :/

Copy link
Member

Choose a reason for hiding this comment

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

should be possible with take here but it didn't work when I tried so I just wonder why :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

take() compiles but then the tests fail. :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Played a bit with this, and not sure there is a super clean solution. You either clone it here, or somehow decouple the closed_fut from self lifetime wise, which is really hard with pinned futures.

@niklasad1
Copy link
Member

@dvdplm can you remove the async-channel in core and ws-server plz before merging this?

Copy link
Contributor

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

Looks good!

Either::Right((None, _)) => {
self.close(&SubscriptionClosed::new(SubscriptionClosedReason::ConnectionReset));
break Ok(());
if let Some(close_notify) = self.close_notify.clone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Played a bit with this, and not sure there is a super clean solution. You either clone it here, or somehow decouple the closed_fut from self lifetime wise, which is really hard with pinned futures.

@dvdplm dvdplm merged commit 7c46458 into master Mar 9, 2022
@dvdplm dvdplm deleted the dp-replace-async_channel branch March 9, 2022 20:16
@niklasad1 niklasad1 mentioned this pull request Apr 4, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core/server]: replace async-channel with tokio::sync::watch in RpcModule
4 participants