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

⚡️ Fix Presence Stream leak #629

Merged
merged 1 commit into from
Oct 10, 2023
Merged

Conversation

alecgibson
Copy link
Collaborator

@alecgibson alecgibson commented Oct 9, 2023

At the moment, when subscribing a Presence multiple times, multiple PubSub Streams are created per-subscription.

However, unsubscribing will only destroy the last created, resulting in streams that are never destroyed.

This change updates our subscription logic to check if we already have an existing stream. If we already have a stream, then we just re-request presence from other clients (which is needed by our DocPresence logic), and return.

Note that we also tweak our unsubscribe logic to eagerly remove the stream after calling destroy (so that subsequent subscribes don't try to reuse a stream that is currently being destroyed).

We also remove a check against seq, which is currently not covered by tests (and actually never calls the callback), so is clearly broken and unneeded anyway.

Depends on

@alecgibson alecgibson force-pushed the presence-subscribe-once branch from 97793c2 to 99315b8 Compare October 10, 2023 08:05
@alecgibson alecgibson force-pushed the subscription-stream-leak branch from cc9c9e9 to dadf3fa Compare October 10, 2023 08:06
Base automatically changed from presence-subscribe-once to master October 10, 2023 16:43
@alecgibson alecgibson force-pushed the subscription-stream-leak branch from dadf3fa to 0270d21 Compare October 10, 2023 16:44
@alecgibson alecgibson marked this pull request as ready for review October 10, 2023 16:44
At the moment, when subscribing a `Presence` multiple times, multiple
PubSub `Stream`s are created per-subscription.

However, unsubscribing will only destroy the [last created][1],
resulting in streams that are never destroyed.

This change updates our subscription logic to check if we already have
an existing stream. If we already have a stream, then we just
re-request presence from other clients (which is needed by our
[`DocPresence` logic][2]), and return.

Note that we also tweak our unsubscribe logic to eagerly remove the
stream after calling destroy (so that subsequent subscribes don't try to
reuse a stream that is currently being destroyed).

We also remove a check against `seq`, which is currently not covered by
tests (and actually never calls the `callback`), so is clearly broken
and unneeded anyway.

[1]: https://github.com/share/sharedb/blob/62e4ec5d46c0dcb097931e9dae60240aaba6b2b3/lib/agent.js#L829-L830
[2]: https://github.com/share/sharedb/blob/62e4ec5d46c0dcb097931e9dae60240aaba6b2b3/lib/client/presence/remote-doc-presence.js#L108-L110
@alecgibson alecgibson force-pushed the subscription-stream-leak branch from 0270d21 to e73b26f Compare October 10, 2023 16:45
@coveralls
Copy link

Coverage Status

coverage: 97.509% (-0.03%) from 97.535% when pulling e73b26f on subscription-stream-leak into dc033c2 on master.

@alecgibson alecgibson merged commit e7e77ba into master Oct 10, 2023
4 checks passed
@alecgibson alecgibson deleted the subscription-stream-leak branch October 10, 2023 16:59
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.

3 participants