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

[1.x] Improve subscription cancellation #195

Merged
merged 20 commits into from
Jan 30, 2023
Merged

Conversation

armiol
Copy link
Contributor

@armiol armiol commented Jan 30, 2023

This PR addresses #188.

In particular, the following changes were made to the behaviour:

  • Calling unsubscribe for any subscription now leads to an immediate cancellation on both client- and server-side. Previously, all such cancellations were only processed during the next "keep-up" propagation.

  • Client now allows cancelling all known subscription via cancelAllSubscriptions() no-args call. Its invocation leads to sending the bulk cancellation request to server-side, as well as shutting down the client-level subscriptions. Such an API is useful in case end-users choose to log out from the application.

Also, this PR aims to improve the server-side memory consumption.

In particular, server-side holds a couple of internal registries to track active subscriptions. Previously, upon cancellation of a subscription, some of these registries were not affected, thus producing a memory leak. Now, each cancelled subscription is removed from all in-memory caches.

In future PRs there will be more updates to this repository, addressing the library updates available for both Java and client-side code.

The library version is set to 1.9.0-SNAPSHOT.10.

@armiol armiol self-assigned this Jan 30, 2023
@armiol armiol marked this pull request as ready for review January 30, 2023 12:19
@armiol
Copy link
Contributor Author

armiol commented Jan 30, 2023

@YegorUdovchenko @dmitrykuzmin since you are the original reporters, please have a look.

@armiol armiol linked an issue Jan 30, 2023 that may be closed by this pull request
@armiol
Copy link
Contributor Author

armiol commented Jan 30, 2023

@YegorUdovchenko @dmitrykuzmin in scope of the following PRs, I am going to update the Firebase Admin SDK to the latest 9.1.x version. This will affect the Java API of web module as well. Please let me know if that's OK with you.

@YegorUdovchenko
Copy link
Collaborator

@YegorUdovchenko @dmitrykuzmin in scope of the following PRs, I am going to update the Firebase Admin SDK to the latest 9.1.x version. This will affect the Java API of web module as well. Please let me know if that's OK with you.

We'll have to version our server API during this migration anyway, so the Admin SDK upgrade is not a big deal.

Copy link
Collaborator

@YegorUdovchenko YegorUdovchenko left a comment

Choose a reason for hiding this comment

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

LGTM. Please see some comments.

@@ -263,12 +275,20 @@ class FirebaseSubscribingClient extends SubscribingClient {
return new EventSubscription({
unsubscribedBy: () => {
FirebaseSubscribingClient._unsubscribe([pathSubscription]);
return this._subscriptionService.cancelSubscription(subscription);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no need to return here, cancelSubscription is void.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well-spotted! I have removed this return just in another use-case, and completely forgot about this one.

cancelSubscription(subscription) {
this._endpoint.cancelSubscription(subscription)
.then(() => {
this._removeSubscription(subscription)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here subscription is a Protobuf message, _removeSubscription expects something derived from RxJS Subscription. I guess we should rework _removeSubscription method so it could remove subscriptions by ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@YegorUdovchenko
That's an interesting point. Perhaps, you are right.

However, I don't understand how this thing worked previously. It uses subscription.internal() objects, which AFAIU are Protobuf messages.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it actually works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@YegorUdovchenko
I have reworked this removal thing to take any kind of Subscription, and operate by its ID. I think, that's the safest approach for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@armiol
Looks ok.

@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Merging #195 (f75bd3a) into v1 (95a0105) will decrease coverage by 0.78%.
The diff coverage is 9.52%.

Additional details and impacted files
@@             Coverage Diff              @@
##                 v1     #195      +/-   ##
============================================
- Coverage     63.17%   62.40%   -0.78%     
- Complexity      214      215       +1     
============================================
  Files            96       96              
  Lines          2724     2761      +37     
  Branches         46       47       +1     
============================================
+ Hits           1721     1723       +2     
- Misses          992     1027      +35     
  Partials         11       11              

Copy link
Contributor

@dmitrykuzmin dmitrykuzmin left a comment

Choose a reason for hiding this comment

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

LGTM.

@armiol armiol merged commit 9de545e into v1 Jan 30, 2023
@armiol armiol deleted the 1.x-improve-unsubscribing branch January 30, 2023 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Reconsider how JS client unsubscribes from subscriptions.
3 participants