-
Notifications
You must be signed in to change notification settings - Fork 252
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
Conversation
There was a problem hiding this 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!
crates/matrix-sdk/src/send_queue.rs
Outdated
/// 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>>>, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
crates/matrix-sdk/src/send_queue.rs
Outdated
transaction_id: OwnedTransactionId, | ||
|
||
/// For an upload request, a trigger to cancel the upload before it | ||
/// completed. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👌 .
Codecov ReportAttention: Patch coverage is
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. |
There can be at most one thing being sent by the send queue, so make this super explicit.
…nail upload is active
de6064c
to
106308c
Compare
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:
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.