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 multiple boosts of a same toot erroneously appearing in TL #14759

Merged
merged 4 commits into from
Sep 7, 2020

Conversation

ClearlyClaire
Copy link
Contributor

@ClearlyClaire ClearlyClaire commented Sep 7, 2020

I have seen and been reported (very rare) cases of multiple consecutive boosts of a same toot appearing in a timeline despite the the “aggregate reblogs” option being checked.

The only possible cause I have identified is the check for a toot having been recently boosted and adding that toot to the set of recently-boosted toots. I am unconvinced this would be the cause, as the time window for such a race condition is extremely narrow, but it would be it is a possible cause, consistent with the reports. I have fixed this race condition.

This is done by using the NX option of Redis' ZADD. I am unsure about the performance implications, but as Redis' documentation does not mention anything related to performances, and that the check was formerly made with a Redis call as complex as ZADD itself (ZREVRANK), I think performances should be better when the posted item is a new reblog, and roughly the same otherwise.

Compatibility-wise, ZADD's NX option has been added in Redis 3.0.2, and we currently require Redis 4 because of Sidekiq, so it should be fine to use.

This PR also includes minor fixups/cleanups/performance improvements.

Instead of using ZREVRANK to determine whether a reblog is a new reblog or not,
use ZADD's NX option to perform the check/addition option atomically.
@ClearlyClaire ClearlyClaire changed the title [WiP] FeedManager improvements Fix race condition possibly causing multiple boosts to appear in TL Sep 7, 2020
@ClearlyClaire ClearlyClaire changed the title Fix race condition possibly causing multiple boosts to appear in TL Fix multiple boosts of a same toot erroneously appearing in TL Sep 7, 2020
@ClearlyClaire ClearlyClaire marked this pull request as ready for review September 7, 2020 14:07
@Gargron Gargron merged commit 517af45 into mastodon:master Sep 7, 2020
thenameisnigel-old pushed a commit to ChatterlyOSE/Chatterly that referenced this pull request Sep 9, 2020
…don#14759)

* Check for and record reblog info atomically

Instead of using ZREVRANK to determine whether a reblog is a new reblog or not,
use ZADD's NX option to perform the check/addition option atomically.

* Replace ZREVRANK call with ZSCORE key which is more efficient

* Make tests a bit stricter

* Fix off-by-one
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.

2 participants