Skip to content

Commit

Permalink
Only retry-able S3 error code will be converted to CRT error code (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK authored Jun 3, 2024
1 parent bc404f4 commit 6588f9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/aws/s3/private/s3_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ void aws_s3_calculate_auto_ranged_get_part_range(
uint64_t *out_part_range_start,
uint64_t *out_part_range_end);

/* Match the S3 error code to CRT error code, return AWS_ERROR_UNKNOWN when not matched */
/* Match the retry-able S3 error code to CRT error code, return AWS_ERROR_UNKNOWN when not matched. */
AWS_S3_API
int aws_s3_crt_error_code_from_server_error_code_string(struct aws_byte_cursor error_code_string);
int aws_s3_crt_error_code_from_recoverable_server_error_code_string(struct aws_byte_cursor error_code_string);

AWS_S3_API
void aws_s3_request_finish_up_metrics_synced(struct aws_s3_request *request, struct aws_s3_meta_request *meta_request);
Expand Down
12 changes: 10 additions & 2 deletions source/s3_meta_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,13 @@ static bool s_should_check_for_error_despite_200_OK(const struct aws_s3_request
return true;
}

/**
* Check the response detail, returns:
* - AWS_ERROR_SUCCESS for successfully response
* - AWS_ERROR_S3_NON_RECOVERABLE_ASYNC_ERROR 200 response with error in the body that is non-recoverable
* - AWS_ERROR_S3_INVALID_RESPONSE_STATUS for all other non-recoverable response.
* - Specific error code for recoverable response.
*/
static int s_s3_meta_request_error_code_from_response(struct aws_s3_request *request) {
AWS_PRECONDITION(request);

Expand All @@ -1520,8 +1527,9 @@ static int s_s3_meta_request_error_code_from_response(struct aws_s3_request *req
struct aws_byte_cursor error_code_string = {0};
const char *xml_path[] = {"Error", "Code", NULL};
if (aws_xml_get_body_at_path(request->allocator, xml_doc, xml_path, &error_code_string) == AWS_OP_SUCCESS) {
/* Found an <Error><Code> string! Map it to CRT error code. */
error_code_from_xml = aws_s3_crt_error_code_from_server_error_code_string(error_code_string);
/* Found an <Error><Code> string! Map it to CRT error code if retry-able. */
error_code_from_xml =
aws_s3_crt_error_code_from_recoverable_server_error_code_string(error_code_string);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/s3_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ int aws_s3_calculate_optimal_mpu_part_size_and_num_parts(
return AWS_OP_SUCCESS;
}

int aws_s3_crt_error_code_from_server_error_code_string(struct aws_byte_cursor error_code_string) {
int aws_s3_crt_error_code_from_recoverable_server_error_code_string(struct aws_byte_cursor error_code_string) {
if (aws_byte_cursor_eq_c_str_ignore_case(&error_code_string, "SlowDown")) {
return AWS_ERROR_S3_SLOW_DOWN;
}
Expand Down

0 comments on commit 6588f9a

Please sign in to comment.