Skip to content

Commit

Permalink
task(send queue): move some assertions back to logged errors
Browse files Browse the repository at this point in the history
Better safe than panicky.
  • Loading branch information
bnjbvr committed Nov 14, 2024
1 parent cefd5a2 commit cb87116
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions crates/matrix-sdk/src/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,13 @@ impl QueueStorage {
transaction_id: request.transaction_id.clone(),
cancel_upload: cancel_upload_tx,
});
assert!(prev.is_none());

if let Some(prev) = prev {
error!(
prev_txn = ?prev.transaction_id,
"a previous request was still active while picking a new one"
);
}

Ok(Some((request.clone(), cancel_upload_rx)))
} else {
Expand All @@ -971,10 +977,11 @@ impl QueueStorage {
/// be removed from the queue later.
async fn mark_as_not_being_sent(&self, transaction_id: &TransactionId) {
let was_being_sent = self.being_sent.write().await.take();
assert_eq!(
was_being_sent.as_ref().map(|info| info.transaction_id.as_ref()),
Some(transaction_id)
);

let prev_txn = was_being_sent.as_ref().map(|info| info.transaction_id.as_ref());
if prev_txn != Some(transaction_id) {
error!(prev_txn = ?prev_txn, "previous active request didn't match that we expect (after transient error)");
}
}

/// Marks a request popped with [`Self::peek_next_to_send`] and identified
Expand All @@ -988,10 +995,11 @@ impl QueueStorage {
// Keep the lock until we're done touching the storage.
let mut being_sent = self.being_sent.write().await;
let was_being_sent = being_sent.take();
assert_eq!(
was_being_sent.as_ref().map(|info| info.transaction_id.as_ref()),
Some(transaction_id)
);

let prev_txn = was_being_sent.as_ref().map(|info| info.transaction_id.as_ref());
if prev_txn != Some(transaction_id) {
error!(prev_txn = ?prev_txn, "previous active request didn't match that we expect (after permanent error)");
}

Ok(self
.client()?
Expand Down Expand Up @@ -1023,10 +1031,11 @@ impl QueueStorage {
// Keep the lock until we're done touching the storage.
let mut being_sent = self.being_sent.write().await;
let was_being_sent = being_sent.take();
assert_eq!(
was_being_sent.as_ref().map(|info| info.transaction_id.as_ref()),
Some(transaction_id)
);

let prev_txn = was_being_sent.as_ref().map(|info| info.transaction_id.as_ref());
if prev_txn != Some(transaction_id) {
error!(prev_txn = ?prev_txn, "previous active request didn't match that we expect (after successful send");
}

let client = self.client()?;
let store = client.store();
Expand Down

0 comments on commit cb87116

Please sign in to comment.