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

deduplicating handler: handle cancellation by repeating the query, if needs be #3533

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Jun 11, 2024

Solves one potential issue spotted in #3529. If the following sequence happened:

  • request A for key K starts
  • request B for key K wants to start, but it's deduplicated, so it waits for request A to finish
  • request A gets aborted

Then, in the previous version of the code, request B would finish and assume that A successfully completed, while this is not the case.

This new version handles that by repeating the deduplicated query. This assumes that it's fine to repeat the entire query, which is not a light assumption, but looking at the uses of the deduplicating handler (/members, sending a read receipt for a room, reading the encryption state for a room), this should be fine.

@bnjbvr bnjbvr requested a review from poljar June 11, 2024 15:44
@bnjbvr bnjbvr requested a review from a team as a code owner June 11, 2024 15:44
Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.78%. Comparing base (abda959) to head (2411dcd).
Report is 19 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk/src/deduplicating_handler.rs 78.57% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3533      +/-   ##
==========================================
- Coverage   83.79%   83.78%   -0.01%     
==========================================
  Files         254      254              
  Lines       25734    25744      +10     
==========================================
+ Hits        21563    21570       +7     
- Misses       4171     4174       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bnjbvr bnjbvr force-pushed the bnjbvr/deduplicating-handler-re-run-query branch from ee3fbef to f958fb7 Compare June 11, 2024 16:06
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Left some minor comments, feel free to ignore if you disagree. Looks good. Thanks for tackling this so swiftly 💪.

/// The query hasn't completed yet. This doesn't mean it hasn't *started*
/// yet, but rather that it couldn't get to completion: some
/// intermediate steps might have run.
NotFinishedYet,
Copy link
Contributor

Choose a reason for hiding this comment

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

NotFinishedYet sounds like we should wait and see if it'll get finished next time, if we're sure that this only happens only if we cancel the future, perhaps Cancelled would be a better name.

// Assume a successful request; we'll modify the result in case of failures
// later.
let request_mutex = Arc::new(Mutex::new(Ok(())));
// Start at the `None` state to indicate we haven't completed the request yet.
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not the None state 😅. I see now why you picked NotFinishedYet, though it still seems that we could say something like:

Let's assume the cancelled state, if we succeed or fail we'll modify the result.

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha, remnant from a previous push. Thanks, I've used Cancelled in lieu of NotFinishedYet, and tweaked the comment accordingly.

(Also added a note about the code future which must be idempotent if run multiple times.)

@bnjbvr bnjbvr enabled auto-merge (rebase) June 12, 2024 13:26
@bnjbvr bnjbvr merged commit 03c16cb into main Jun 12, 2024
38 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/deduplicating-handler-re-run-query branch June 12, 2024 13:39
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