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

feat(send queue): allow aborting a media upload #4262

Merged
merged 5 commits into from
Nov 14, 2024
Merged

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Nov 13, 2024

This is a bit tricky, because we need to care about all possible states of the sending state machine, and do something different in each case:

  • has the thumbnail upload started yet? y/n
  • has the file upload staretd yet? y/n
  • has the media event been sent yet? y/n

Fortunately, it's pretty easy to test all the cases, so I've done just that. Many LOCs are just tests, so don't be too afraid by it.

Part of #4201.

@bnjbvr bnjbvr requested a review from a team as a code owner November 13, 2024 17:08
@bnjbvr bnjbvr requested review from jmartinesp and removed request for a team November 13, 2024 17:08
Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple of minor comments and a question!

Comment on lines 833 to 836
/// All the queued requests that are being sent at the moment.
///
/// It also serves as an internal lock on the storage backend.
being_sent: Arc<RwLock<BTreeSet<OwnedTransactionId>>>,
being_sent: Arc<RwLock<Option<OwnedTransactionId>>>,
Copy link
Contributor

@jmartinesp jmartinesp Nov 14, 2024

Choose a reason for hiding this comment

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

Maybe the doc comment doesn't match anymore as there is only 1 request at a time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

transaction_id: OwnedTransactionId,

/// For an upload request, a trigger to cancel the upload before it
/// completed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor typo maybe? Either 'it's completed' or 'it completes'.

if let Some(info) = being_sent.as_ref() {
if info.transaction_id == *thumbnail_txn {
// SAFETY: we knew it was Some(), two lines above.
let info = being_sent.take().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Rookie Rust dev question: why do we need another info here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question! Above it was taken as_ref(), so a &BeingSentInfo; the cancellation requires triggering the oneshot::channel, which consumes it by ownership, so we need to take BeingSentInfo by ownership here; at this point it's fine because we know it's the last use. I'll add a comment and maybe a tiny function helper to make this clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, I didn't realise the channel is consumed 👌 .

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 88.18898% with 15 lines in your changes missing coverage. Please review.

Project coverage is 84.95%. Comparing base (7aa930b) to head (106308c).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/send_queue.rs 82.85% 12 Missing ⚠️
crates/matrix-sdk/src/send_queue/upload.rs 94.73% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4262      +/-   ##
==========================================
+ Coverage   84.92%   84.95%   +0.02%     
==========================================
  Files         274      274              
  Lines       29858    29939      +81     
==========================================
+ Hits        25358    25434      +76     
- Misses       4500     4505       +5     

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

@bnjbvr bnjbvr enabled auto-merge (rebase) November 14, 2024 14:20
@bnjbvr bnjbvr merged commit 9b6de4e into main Nov 14, 2024
40 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/send-queue-abort branch November 14, 2024 14:34
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