From a592a470cf4444ca8ed3d77cbfea8a92bcce7642 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 5 Oct 2024 09:32:56 +0000 Subject: [PATCH] fix: make backup reception cancellable by stopping ongoing process This is already documented in JSON-RPC API, but in fact ongoing process was not allocated. --- src/imex/transfer.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/imex/transfer.rs b/src/imex/transfer.rs index 15f87c794..4f9b12591 100644 --- a/src/imex/transfer.rs +++ b/src/imex/transfer.rs @@ -345,7 +345,17 @@ pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> { Qr::Backup2 { node_addr, auth_token, - } => get_backup2(context, node_addr, auth_token).await?, + } => { + let cancel_token = context.alloc_ongoing().await?; + let res = get_backup2(context, node_addr, auth_token) + .race(async { + cancel_token.recv().await.ok(); + Err(format_err!("Backup reception cancelled")) + }) + .await; + context.free_ongoing().await; + res?; + } _ => bail!("QR code for backup must be of type DCBACKUP2"), } Ok(())