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) <noreply@anthropic.com>
This commit is contained in:
@@ -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<Vec<u8>> {
|
||||
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}"
|
||||
|
||||
Reference in New Issue
Block a user