Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: abort multipart upload if chunk PutObject request failed #274

Merged
merged 1 commit into from Jul 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 43 additions & 6 deletions s3/src/bucket.rs
Expand Up @@ -889,8 +889,21 @@ impl Bucket {
multipart: Some(Multipart::new(part_number, upload_id)), // upload_id: &msg.upload_id,
};
let request = RequestImpl::new(self, &path, command);
let (data, _code) = request.response_data(true).await?;
let etag = std::str::from_utf8(data.as_slice())?;
let (chunk_data, chunk_code) = request.response_data(true).await?;

if !(200..300).contains(&chunk_code) {
// if chunk upload failed - abort the upload
match self.abort_upload(&path, upload_id).await {
Ok(_) => {
return Err(error_from_response_data(chunk_data, chunk_code)?);
}
Err(error) => {
return Err(error);
}
}
}

let etag = std::str::from_utf8(chunk_data.as_slice())?;
etags.push(etag.to_string());

if chunk.len() < CHUNK_SIZE {
Expand Down Expand Up @@ -956,8 +969,20 @@ impl Bucket {
multipart: Some(Multipart::new(part_number, upload_id)), // upload_id: &msg.upload_id,
};
let request = RequestImpl::new(self, &path, command);
let (data, _code) = request.response_data(true)?;
let etag = std::str::from_utf8(data.as_slice())?;
let (chunk_data, chunk_code) = request.response_data(true)?;
if !(200..300).contains(&chunk_code) {
// if chunk upload failed - abort the upload
match self.abort_upload(&path, upload_id) {
Ok(_) => {
return Err(error_from_response_data(chunk_data, chunk_code)?);
}
Err(error) => {
return Err(error);
}
}
}

let etag = std::str::from_utf8(chunk_data.as_slice())?;
etags.push(etag.to_string());
let inner_data = etags
.into_iter()
Expand Down Expand Up @@ -985,8 +1010,20 @@ impl Bucket {
multipart: Some(Multipart::new(part_number, upload_id)),
};
let request = RequestImpl::new(self, &path, command);
let (data, _code) = request.response_data(true)?;
let etag = std::str::from_utf8(data.as_slice())?;
let (chunk_data, chunk_code) = request.response_data(true)?;
if !(200..300).contains(&chunk_code) {
// if chunk upload failed - abort the upload
match self.abort_upload(&path, upload_id) {
Ok(_) => {
return Err(error_from_response_data(chunk_data, chunk_code)?);
}
Err(error) => {
return Err(error);
}
}
}

let etag = std::str::from_utf8(chunk_data.as_slice())?;
etags.push(etag.to_string());
}
}
Expand Down