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.destroy() race condition #645

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

alecgibson
Copy link
Collaborator

There's currently a race condition that can throw uncaught errors when destroying both a LocalPresence and its parent Presence object.

If the LocalPresence destroys first, then - since the Presence cached its ID before the Presence unsubscribe - by the time the Presence tries to destroy its children, the LocalPresence is already gone, which throws when trying to call destroy().

This change adds a test for this race condition, and adds a fix, which just checks if the LocalPresence still exists on the parent before trying to destroy it.

There's currently a race condition that can throw uncaught errors when
destroying both a `LocalPresence` *and* its parent `Presence` object.

If the `LocalPresence` destroys first, then - since the `Presence`
[cached][1] its ID before the `Presence` unsubscribe - by the time the
`Presence` tries to destroy its children, the `LocalPresence` is already
gone, which throws when [trying to call `destroy()`][2].

This change adds a test for this race condition, and adds a fix, which
just checks if the `LocalPresence` still exists on the parent before
trying to destroy it.

[1]: https://github.com/share/sharedb/blob/91cae28a0065faf68749243ef36aadf54bf0645d/lib/client/presence/presence.js#L56
[2]: https://github.com/share/sharedb/blob/91cae28a0065faf68749243ef36aadf54bf0645d/lib/client/presence/presence.js#L64
@coveralls
Copy link

Coverage Status

coverage: 97.503% (+0.002%) from 97.501%
when pulling b975ab1 on local-presence-destroy-race
into 91cae28 on master.

@alecgibson alecgibson merged commit f02dad8 into master Mar 28, 2024
8 checks passed
@alecgibson alecgibson deleted the local-presence-destroy-race branch March 28, 2024 08:01
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