From 366089e2910b5ec655ef8fd3b06f7ebd77d6f696 Mon Sep 17 00:00:00 2001 From: sindoring Date: Tue, 27 Oct 2026 13:11:19 +0400 Subject: [PATCH] moonwell-deploy: a failed multipart part is sent again Publishing Project Reforged's patch-A.mpq (1.7 GB) failed four times at a random part (27, 85, 5, 24), and each failure aborted the upload and restarted the file from part 1. A part is now sent up to six times with a doubling pause (4 s to 64 s) before the upload fails, and the failure names the store's error instead of dropping it. Verified: builds and lints clean; the release publish is running with it. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/moonwell-deploy/src/storage.rs | 36 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/moonwell-deploy/src/storage.rs b/crates/moonwell-deploy/src/storage.rs index 2de929a6d..21a36697c 100644 --- a/crates/moonwell-deploy/src/storage.rs +++ b/crates/moonwell-deploy/src/storage.rs @@ -24,6 +24,8 @@ pub struct S3Store { const PART_BYTES: usize = s3::bucket::CHUNK_SIZE; const UPLOAD_WORKERS: usize = 4; +/// How many times one multipart part is sent before the upload fails. +const PART_ATTEMPTS: u32 = 6; fn read_part(reader: &mut impl Read) -> Result> { let mut bytes = Vec::with_capacity(PART_BYTES); @@ -141,14 +143,32 @@ impl S3Store { let upload_id = &upload.upload_id; handles.push(scope.spawn(move || { let expected = format!("{:x}", md5::compute(&bytes)); - let part = self - .bucket - .put_multipart_chunk(&bytes, key, number, upload_id, content_type) - .map_err(|_| { - anyhow::anyhow!( - "S3 multipart upload failed for {key}, part {number}" - ) - })?; + // A part that fails is sent again, so one dropped connection does + // not restart a gigabyte file from its first part. + let mut attempt = 0; + let part = loop { + attempt += 1; + match self.bucket.put_multipart_chunk( + &bytes, + key, + number, + upload_id, + content_type, + ) { + Ok(part) => break part, + Err(e) if attempt < PART_ATTEMPTS => { + eprintln!( + "S3 part {number} of {key}, attempt {attempt}: {e}; retrying" + ); + std::thread::sleep(std::time::Duration::from_secs( + 2u64 << attempt, + )); + } + Err(e) => anyhow::bail!( + "S3 multipart upload failed for {key}, part {number}: {e}" + ), + } + }; ensure!( part.etag.trim_matches('"') == expected, "S3 part checksum mismatch for {key}, part {number}"