From 41779e62696074ae98215ec295c31809c855592b Mon Sep 17 00:00:00 2001 From: helmutcarter Date: Wed, 25 Mar 2026 11:38:20 -0400 Subject: [PATCH 1/2] fix(bug): prevent race condition --- rslib/src/backend/sync.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rslib/src/backend/sync.rs b/rslib/src/backend/sync.rs index fc198e8da5a..8e30defee1a 100644 --- a/rslib/src/backend/sync.rs +++ b/rslib/src/backend/sync.rs @@ -200,9 +200,11 @@ impl Backend { task.take(); } } + let (abort_handle, abort_reg) = AbortHandle::new_pair(); + self.state.lock().unwrap().sync.media_sync_abort = Some(abort_handle); let backend = self.clone(); *task = Some(std::thread::spawn(move || { - backend.sync_media_blocking(auth, server_usn) + backend.sync_media_blocking(auth, server_usn, abort_reg) })); Ok(()) } @@ -238,15 +240,16 @@ impl Backend { &self, auth: SyncAuth, server_usn: Option, + abort_reg: AbortRegistration, ) -> Result<()> { - // abort handle - let (abort_handle, abort_reg) = AbortHandle::new_pair(); - self.state.lock().unwrap().sync.media_sync_abort = Some(abort_handle); + let _clear_abort_handle = scopeguard::guard(self.clone(), |backend| { + backend.state.lock().unwrap().sync.media_sync_abort.take(); + }); // start the sync let (mgr, progress) = { let mut col = self.col.lock().unwrap(); - let col = col.as_mut().unwrap(); + let col = col.as_mut().ok_or(AnkiError::CollectionNotOpen)?; (col.media()?, col.new_progress_handler()) }; let rt = self.runtime_handle(); @@ -254,9 +257,6 @@ impl Backend { let abortable_sync = Abortable::new(sync_fut, abort_reg); let result = rt.block_on(abortable_sync); - // clean up the handle - self.state.lock().unwrap().sync.media_sync_abort.take(); - // return result match result { Ok(sync_result) => sync_result, From c653c72d5e162609c8fb392de004323f099c0b79 Mon Sep 17 00:00:00 2001 From: helmut carter <78439990+helmutcarter@users.noreply.github.com> Date: Wed, 25 Mar 2026 11:46:12 -0400 Subject: [PATCH 2/2] Add myself to CONTRIBUTORS Hope it's okay to use my github url instead of my email, I don't really want to put my personal email out there. --- CONTRIBUTORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a3b1b1c6f84..7fad706c20c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -266,7 +266,7 @@ Yuuki Gabriele Patriarca SecretX Daniel Pechersky fernandolins <1887601+fernandolins@users.noreply.github.com> - +Helmut Carter ******************** The text of the 3 clause BSD license follows: