From 2ec0cb7fa66ea42cd129396f987dc207c6c5d9d4 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 2 Feb 2026 22:31:08 -0800 Subject: fix: halt sync loop if server returns an empty page (#3122) We had an issue where the server was returning an empty page, when it should not, and causing the client to keep looping While such bugs should not happen, putting the client into a loop does not help ## Checks - [ ] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [ ] I have checked that there are no existing pull requests for the same thing --- crates/atuin-client/src/record/sync.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/atuin-client/src') diff --git a/crates/atuin-client/src/record/sync.rs b/crates/atuin-client/src/record/sync.rs index 1c6b0e01..a47f100b 100644 --- a/crates/atuin-client/src/record/sync.rs +++ b/crates/atuin-client/src/record/sync.rs @@ -182,7 +182,6 @@ async fn sync_upload( tag ); - // preload with the first entry if remote does not know of this store loop { let page = store .next(host, tag.as_str(), remote + progress, upload_page_size) @@ -193,14 +192,18 @@ async fn sync_upload( SyncError::LocalStoreError { msg: e.to_string() } })?; + if page.is_empty() { + break; + } + client.post_records(&page).await.map_err(|e| { error!("failed to post records: {e:?}"); SyncError::RemoteRequestError { msg: e.to_string() } })?; - pb.set_position(progress); progress += page.len() as u64; + pb.set_position(progress); if progress >= expected { break; @@ -239,13 +242,16 @@ async fn sync_download( .with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()) .progress_chars("#>-")); - // preload with the first entry if remote does not know of this store loop { let page = client .next_records(host, tag.clone(), local + progress, download_page_size) .await .map_err(|e| SyncError::RemoteRequestError { msg: e.to_string() })?; + if page.is_empty() { + break; + } + store .push_batch(page.iter()) .await @@ -253,8 +259,8 @@ async fn sync_download( ret.extend(page.iter().map(|f| f.id)); - pb.set_position(progress); progress += page.len() as u64; + pb.set_position(progress); if progress >= expected { break; -- cgit v1.3.1