Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

fix(core): a busy database no longer cancels a queued send

Beef9ab5510dd6d
diff --git a/core/nectarlink-core/src/transfer.rs b/core/nectarlink-core/src/transfer.rs
index ae10c68..c65fba8 100644
--- a/core/nectarlink-core/src/transfer.rs
+++ b/core/nectarlink-core/src/transfer.rs
@@ -845,6 +845,7 @@ pub(crate) async fn deliver_queued_files(
let mut attempts = item.attempts;
const RETRY_BACKOFF_MS: [i64; 5] = [1_000, 2_000, 4_000, 8_000, 15_000];
+ let mut store_errors = 0u32;
let state = loop {
if cancel.is_cancelled() {
break TransferState::Cancelled;
@@ -852,9 +853,24 @@ pub(crate) async fn deliver_queued_files(
if shutdown.is_cancelled() {
break TransferState::Failed(TransferFailure::Interrupted);
}
- let Ok(Some((current, _, _, _))) = shared.store.get_queue_item(&item.id) else {
- break TransferState::Cancelled;
+ let current = match shared.store.get_queue_item(&item.id) {
+ Ok(Some((current, _, _, _))) => current,
+ // Removed from the queue: the user cancelled it.
+ Ok(None) => break TransferState::Cancelled,
+ // The database was busy for a moment; that's not a cancel.
+ Err(e) if store_errors < 20 => {
+ store_errors += 1;
+ tracing::debug!(error = %e, "can't read the queue item yet");
+ tokio::time::sleep(Duration::from_millis(250)).await;
+ continue;
+ }
+ Err(e) => {
+ break TransferState::Failed(TransferFailure::Other(format!(
+ "can't read the send queue: {e}"
+ )));
+ }
};
+ store_errors = 0;
if let crate::QueueStatus::Failed { error } | crate::QueueStatus::Expired { error } = current.status {
break TransferState::Failed(TransferFailure::Other(error));
}