Debian Codegraph @

crt/aws-c-s3/source/s3_auto_ranged_get.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include "aws/s3/private/s3_auto_ranged_get.h"
7 #include "aws/s3/private/s3_client_impl.h"
8 #include "aws/s3/private/s3_meta_request_impl.h"
9 #include "aws/s3/private/s3_request_messages.h"
10 #include "aws/s3/private/s3_util.h"
11 #include <aws/common/string.h>
12 #include <aws/common/system_info.h>
13 #include <inttypes.h>
14
15 /* Dont use buffer pool when we know response size, and its below this number,
16 * i.e. when user provides explicit range that is small, ex. range = 1-100.
17 * Instead of going through the pool in that case, we just use a dynamic buffer
18 * for response (pre-mempool behavior). */
19 const uint64_t s_min_size_response_for_pooling = 1 * 1024 * 1024;
20 const uint32_t s_conservative_max_requests_in_flight = 8;
21 const struct aws_byte_cursor g_application_xml_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("application/xml");
22
23 static void s_s3_meta_request_auto_ranged_get_destroy(struct aws_s3_meta_request *meta_request);
24
25 static bool s_s3_auto_ranged_get_update(
26 struct aws_s3_meta_request *meta_request,
27 uint32_t flags,
28 struct aws_s3_request **out_request);
29
30 static struct aws_future_void *s_s3_auto_ranged_get_prepare_request(struct aws_s3_request *request);
31
32 static void s_s3_auto_ranged_get_request_finished(
33 struct aws_s3_meta_request *meta_request,
34 struct aws_s3_request *request,
35 int error_code);
36
37 static struct aws_s3_meta_request_vtable s_s3_auto_ranged_get_vtable = {
38 .update = s_s3_auto_ranged_get_update,
39 .send_request_finish = aws_s3_meta_request_send_request_finish_default,
40 .prepare_request = s_s3_auto_ranged_get_prepare_request,
41 .init_signing_date_time = aws_s3_meta_request_init_signing_date_time_default,
42 .sign_request = aws_s3_meta_request_sign_request_default,
43 .finished_request = s_s3_auto_ranged_get_request_finished,
44 .destroy = s_s3_meta_request_auto_ranged_get_destroy,
45 .finish = aws_s3_meta_request_finish_default,
46 };
47
48 static int s_s3_auto_ranged_get_success_status(struct aws_s3_meta_request *meta_request) {
49 AWS_PRECONDITION(meta_request);
50
51 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
52 AWS_PRECONDITION(auto_ranged_get);
53
54 if (auto_ranged_get->initial_message_has_range_header) {
55 return AWS_HTTP_STATUS_CODE_206_PARTIAL_CONTENT;
56 }
57
58 return AWS_HTTP_STATUS_CODE_200_OK;
59 }
60
61 /* Allocate a new auto-ranged-get meta request. */
62 struct aws_s3_meta_request *aws_s3_meta_request_auto_ranged_get_new(
63 struct aws_allocator *allocator,
64 struct aws_s3_client *client,
65 size_t part_size,
66 bool part_size_set,
67 const struct aws_s3_meta_request_options *options) {
68 AWS_PRECONDITION(allocator);
69 AWS_PRECONDITION(client);
70 AWS_PRECONDITION(options);
71 AWS_PRECONDITION(options->message);
72
73 struct aws_s3_auto_ranged_get *auto_ranged_get =
74 aws_mem_calloc(allocator, 1, sizeof(struct aws_s3_auto_ranged_get));
75
76 /* Try to initialize the base type. */
77 if (aws_s3_meta_request_init_base(
78 allocator,
79 client,
80 part_size,
81 false,
82 false,
83 options,
84 auto_ranged_get,
85 &s_s3_auto_ranged_get_vtable,
86 &auto_ranged_get->base)) {
87
88 AWS_LOGF_ERROR(
89 AWS_LS_S3_META_REQUEST,
90 "id=%p Could not initialize base type for Auto-Ranged-Get Meta Request.",
91 (void *)auto_ranged_get);
92 aws_mem_release(allocator, auto_ranged_get);
93 return NULL;
94 }
95
96 auto_ranged_get->part_size_set = part_size_set;
97 auto_ranged_get->force_dynamic_part_size = options->force_dynamic_part_size;
98 struct aws_http_headers *headers = aws_http_message_get_headers(auto_ranged_get->base.initial_request_message);
99 AWS_ASSERT(headers != NULL);
100
101 if (aws_http_headers_has(headers, g_range_header_name)) {
102 auto_ranged_get->initial_message_has_range_header = true;
103 if (aws_s3_parse_request_range_header(
104 headers,
105 &auto_ranged_get->initial_message_has_start_range,
106 &auto_ranged_get->initial_message_has_end_range,
107 &auto_ranged_get->initial_range_start,
108 &auto_ranged_get->initial_range_end)) {
109 AWS_LOGF_ERROR(
110 AWS_LS_S3_META_REQUEST,
111 "id=%p Could not parse Range header for Auto-Ranged-Get Meta Request.",
112 (void *)auto_ranged_get);
113 goto on_error;
114 }
115 }
116 auto_ranged_get->initial_message_has_if_match_header = aws_http_headers_has(headers, g_if_match_header_name);
117
118 auto_ranged_get->synced_data.first_part_size = auto_ranged_get->base.part_size;
119 if (options->object_size_hint != NULL) {
120 auto_ranged_get->object_size_hint_available = true;
121 auto_ranged_get->object_size_hint = *options->object_size_hint;
122 }
123 AWS_LOGF_DEBUG(
124 AWS_LS_S3_META_REQUEST, "id=%p Created new Auto-Ranged Get Meta Request.", (void *)&auto_ranged_get->base);
125
126 return &auto_ranged_get->base;
127
128 on_error:
129 /* This will also clean up the auto_ranged_get */
130 aws_s3_meta_request_release(&(auto_ranged_get->base));
131 return NULL;
132 }
133
134 static void s_s3_meta_request_auto_ranged_get_destroy(struct aws_s3_meta_request *meta_request) {
135 AWS_PRECONDITION(meta_request);
136 AWS_PRECONDITION(meta_request->impl);
137
138 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
139 aws_string_destroy(auto_ranged_get->etag);
140 aws_mem_release(meta_request->allocator, auto_ranged_get);
141 }
142
143 /*
144 * This function returns the type of first request which we will also use to discover overall object size.
145 */
146 static enum aws_s3_auto_ranged_get_request_type s_s3_get_request_type_for_discovering_object_size(
147 const struct aws_s3_meta_request *meta_request) {
148 AWS_PRECONDITION(meta_request);
149 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
150 AWS_ASSERT(auto_ranged_get);
151
152 /*
153 * When we attempt to download an empty file using the `AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE`
154 * request type, the request fails with an empty file error. We then reset `object_range_known`
155 * (`object_range_empty` is set to true) and try to download the file again with
156 * `AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1`. We send another request, even though there is
157 * no body, to provide successful response headers to the user. If the file is still empty, successful response
158 * headers will be provided to the users. Otherwise, the newer version of the file will be downloaded.
159 */
160 if (auto_ranged_get->synced_data.object_range_empty != 0) {
161 auto_ranged_get->synced_data.object_range_empty = 0;
162 return AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1;
163 }
164
165 /*
166 * If a range header exists but has no start-range (i.e. Range: bytes=-100), we perform a HeadRequest. If the
167 * start-range is unknown, we could potentially execute a request from the end-range and keep that request around
168 * until the meta request finishes. However, this approach involves the complexity of managing backpressure. For
169 * simplicity, we execute a HeadRequest if the start-range is not specified.
170 */
171 if (auto_ranged_get->initial_message_has_range_header != 0) {
172 return auto_ranged_get->initial_message_has_start_range
173 ? AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE
174 : AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT;
175 }
176
177 /* If the object_size_hint indicates that it fits in a single part, try to get the file directly.
178 * This avoids a HEAD request and sizes the buffer reservation to the hint rather than full part_size.
179 * If the hint is wrong and the object is larger, the request will be cancelled and retried with ranged gets. */
180 if (auto_ranged_get->object_size_hint_available && auto_ranged_get->object_size_hint > 0 &&
181 auto_ranged_get->object_size_hint <= meta_request->part_size) {
182 return AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1;
183 }
184
185 /* If we don't need checksum validation, then discover the size of the object while trying to get the first part. */
186 if (!meta_request->checksum_config.validate_response_checksum) {
187 return AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE;
188 }
189
190 /* Otherwise, do a headObject so that we can validate checksum if the file was uploaded as a single part */
191 return AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT;
192 }
193
194 static bool s_s3_auto_ranged_get_update(
195 struct aws_s3_meta_request *meta_request,
196 uint32_t flags,
197 struct aws_s3_request **out_request) {
198 AWS_PRECONDITION(meta_request);
199 AWS_PRECONDITION(out_request);
200
201 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
202 struct aws_s3_request *request = NULL;
203 bool work_remaining = false;
204
205 /* BEGIN CRITICAL SECTION */
206 {
207 aws_s3_meta_request_lock_synced_data(meta_request);
208
209 #ifdef AWS_C_S3_ENABLE_TEST_STUBS
210 if (meta_request->vtable->synced_update_stub && meta_request->vtable->synced_update_stub(meta_request)) {
211 /* TEST ONLY, allow test to stub here. */
212 aws_s3_meta_request_unlock_synced_data(meta_request);
213 return true;
214 }
215 #endif
216 /* If nothing has set the "finish result" then this meta request is still in progress, and we can potentially
217 * send additional requests. */
218 if (!aws_s3_meta_request_has_finish_result_synced(meta_request)) {
219
220 if ((flags & AWS_S3_META_REQUEST_UPDATE_FLAG_CONSERVATIVE) != 0) {
221 uint32_t num_requests_in_flight =
222 (auto_ranged_get->synced_data.num_parts_requested -
223 auto_ranged_get->synced_data.num_parts_completed) +
224 (uint32_t)aws_priority_queue_size(&meta_request->synced_data.pending_body_streaming_requests);
225
226 /* auto-ranged-gets make use of body streaming, which will hold onto response bodies if parts earlier in
227 * the file haven't arrived yet. This can potentially create a lot of backed up requests, causing us to
228 * hit our global request limit. To help mitigate this, when the "conservative" flag is passed in, we
229 * only allow the total amount of requests being sent/streamed to be inside a set limit. */
230 if (num_requests_in_flight > s_conservative_max_requests_in_flight) {
231 goto has_work_remaining;
232 }
233 }
234
235 /* If the overall range of the object that we are trying to retrieve isn't known yet, then we need to send a
236 * request to figure that out. */
237 if (!auto_ranged_get->synced_data.object_range_known) {
238 if (auto_ranged_get->synced_data.head_object_sent ||
239 auto_ranged_get->synced_data.num_parts_requested > 0) {
240 goto has_work_remaining;
241 }
242 switch (s_s3_get_request_type_for_discovering_object_size(meta_request)) {
243 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT:
244 AWS_LOGF_INFO(
245 AWS_LS_S3_META_REQUEST,
246 "id=%p: Doing a HeadObject to discover the size of the object",
247 (void *)meta_request);
248 request = aws_s3_request_new(
249 meta_request,
250 AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT,
251 AWS_S3_REQUEST_TYPE_HEAD_OBJECT,
252 0 /*part_number*/,
253 AWS_S3_REQUEST_FLAG_RECORD_RESPONSE_HEADERS);
254 auto_ranged_get->synced_data.head_object_sent = true;
255 break;
256 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1:
257 AWS_LOGF_INFO(
258 AWS_LS_S3_META_REQUEST,
259 "id=%p: Doing a 'GET_OBJECT_WITH_PART_NUMBER_1' to discover the size of the object and get "
260 "the first part",
261 (void *)meta_request);
262
263 request = aws_s3_request_new(
264 meta_request,
265 AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1,
266 AWS_S3_REQUEST_TYPE_GET_OBJECT,
267 1 /*part_number*/,
268 AWS_S3_REQUEST_FLAG_RECORD_RESPONSE_HEADERS |
269 AWS_S3_REQUEST_FLAG_ALLOCATE_BUFFER_FROM_POOL);
270 /* Reserve only as much buffer as the hint suggests, capped at part_size.
271 * If the hint is absent or zero, fall back to the full part_size reservation.
272 * If the hint turns out to be too small, the cancellation in
273 * s_s3_meta_request_headers_block_done fires before the body arrives, and the
274 * mismatch handling below keeps the discovered size and fetches the data as
275 * ranged gets instead of re-issuing a partNumber request. */
276 request->part_range_start = 0;
277 request->part_range_end =
278 (auto_ranged_get->object_size_hint_available && auto_ranged_get->object_size_hint > 0)
279 ? aws_min_u64(auto_ranged_get->object_size_hint, meta_request->part_size) - 1
280 : meta_request->part_size - 1;
281 ++auto_ranged_get->synced_data.num_parts_requested;
282
283 break;
284 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE:
285 AWS_LOGF_INFO(
286 AWS_LS_S3_META_REQUEST,
287 "id=%p: Doing a 'GET_OBJECT_WITH_RANGE' to discover the size of the object and get the "
288 "first part",
289 (void *)meta_request);
290
291 uint64_t part_range_start = 0;
292 uint64_t first_part_size = meta_request->part_size;
293 if (auto_ranged_get->initial_message_has_range_header) {
294 /*
295 * Currently, we only discover the size of the object when the initial range header includes
296 * a start-range. If we ever implement skipping the HeadRequest for a Range request without
297 * a start-range, this will need to update.
298 */
299 AWS_ASSERT(auto_ranged_get->initial_message_has_start_range);
300 part_range_start = auto_ranged_get->initial_range_start;
301
302 if (auto_ranged_get->initial_message_has_end_range) {
303 first_part_size = aws_min_u64(
304 first_part_size,
305 auto_ranged_get->initial_range_end - auto_ranged_get->initial_range_start + 1);
306 }
307
308 auto_ranged_get->synced_data.first_part_size = first_part_size;
309 }
310 AWS_LOGF_INFO(
311 AWS_LS_S3_META_REQUEST,
312 "id=%p: Doing a ranged get to discover the size of the object and get the first part",
313 (void *)meta_request);
314
315 request = aws_s3_request_new(
316 meta_request,
317 AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE,
318 AWS_S3_REQUEST_TYPE_GET_OBJECT,
319 1 /*part_number*/,
320 AWS_S3_REQUEST_FLAG_RECORD_RESPONSE_HEADERS |
321 AWS_S3_REQUEST_FLAG_ALLOCATE_BUFFER_FROM_POOL);
322 request->part_range_start = part_range_start;
323 request->part_range_end = part_range_start + first_part_size - 1; /* range-end is inclusive */
324 ++auto_ranged_get->synced_data.num_parts_requested;
325 break;
326 default:
327 AWS_FATAL_ASSERT(
328 0 && "s_s3_get_request_type_for_discovering_object_size returned unexpected discover "
329 "object size request type");
330 }
331 request->discovers_object_size = true;
332 goto has_work_remaining;
333 }
334
335 /* If there are still more parts to be requested */
336 if (auto_ranged_get->synced_data.num_parts_requested < auto_ranged_get->synced_data.total_num_parts) {
337
338 if (meta_request->client->enable_read_backpressure) {
339 /* Don't start a part until we have enough window to send bytes to the user.
340 *
341 * Note that we start a part once we have enough window to deliver ANY of its bytes.
342 * If we waited until the window was large enough for the WHOLE part,
343 * we could end up stuck in a situation where the user is
344 * waiting for more bytes before they'll open the window,
345 * and this implementation is waiting for more window before it will send more parts. */
346 uint64_t read_data_requested = 0;
347 if (auto_ranged_get->synced_data.num_parts_requested > 0) {
348 read_data_requested =
349 (auto_ranged_get->synced_data.num_parts_requested - 1) * meta_request->part_size +
350 auto_ranged_get->synced_data.first_part_size;
351 }
352 if (read_data_requested >= meta_request->synced_data.read_window_running_total) {
353
354 /* Avoid spamming users with this DEBUG message */
355 if (auto_ranged_get->synced_data.read_window_warning_issued == 0) {
356 auto_ranged_get->synced_data.read_window_warning_issued = 1;
357
358 AWS_LOGF_DEBUG(
359 AWS_LS_S3_META_REQUEST,
360 "id=%p: Download paused because read window is zero. "
361 "You must increment to window to continue.",
362 (void *)meta_request);
363 }
364
365 goto has_work_remaining;
366 }
367
368 auto_ranged_get->synced_data.read_window_warning_issued = 0;
369 }
370
371 request = aws_s3_request_new(
372 meta_request,
373 AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE,
374 AWS_S3_REQUEST_TYPE_GET_OBJECT,
375 auto_ranged_get->synced_data.num_parts_requested + 1 /*part_number*/,
376 AWS_S3_REQUEST_FLAG_ALLOCATE_BUFFER_FROM_POOL);
377
378 aws_s3_calculate_auto_ranged_get_part_range(
379 auto_ranged_get->synced_data.object_range_start,
380 auto_ranged_get->synced_data.object_range_end,
381 meta_request->part_size,
382 auto_ranged_get->synced_data.first_part_size,
383 request->part_number,
384 &request->part_range_start,
385 &request->part_range_end);
386
387 ++auto_ranged_get->synced_data.num_parts_requested;
388 goto has_work_remaining;
389 }
390
391 /* If there are parts that have not attempted delivery to the caller, then there is still work being done.
392 */
393 if (meta_request->synced_data.num_parts_delivery_completed < auto_ranged_get->synced_data.total_num_parts) {
394 goto has_work_remaining;
395 }
396 } else {
397 /* Else, if there is a finish result set, make sure that all work-in-progress winds down before the meta
398 * request completely exits. */
399
400 if (auto_ranged_get->synced_data.head_object_sent && !auto_ranged_get->synced_data.head_object_completed) {
401 goto has_work_remaining;
402 }
403
404 /* Wait for all requests to complete (successfully or unsuccessfully) before finishing.*/
405 if (auto_ranged_get->synced_data.num_parts_completed < auto_ranged_get->synced_data.num_parts_requested) {
406 goto has_work_remaining;
407 }
408
409 /* If some parts are still being delivered to the caller, then wait for those to finish. */
410 if (meta_request->synced_data.num_parts_delivery_completed <
411 meta_request->synced_data.num_parts_delivery_sent) {
412 goto has_work_remaining;
413 }
414 }
415
416 goto no_work_remaining;
417
418 has_work_remaining:
419 work_remaining = true;
420
421 if (request != NULL) {
422 AWS_LOGF_DEBUG(
423 AWS_LS_S3_META_REQUEST,
424 "id=%p: Returning request %p for part %d of %d",
425 (void *)meta_request,
426 (void *)request,
427 request->part_number,
428 auto_ranged_get->synced_data.total_num_parts);
429 }
430
431 no_work_remaining:
432 /* If some events are still being delivered to caller, then wait for those to finish */
433 if (!work_remaining && aws_s3_meta_request_are_events_out_for_delivery_synced(meta_request)) {
434 work_remaining = true;
435 }
436
437 if (!work_remaining) {
438 aws_s3_meta_request_set_success_synced(meta_request, s_s3_auto_ranged_get_success_status(meta_request));
439 if (auto_ranged_get->synced_data.num_parts_checksum_validated ==
440 auto_ranged_get->synced_data.num_parts_requested) {
441 /* If we have validated the checksum for every part, we set the meta request level checksum validation
442 * result.*/
443 meta_request->synced_data.finish_result.did_validate = true;
444 meta_request->synced_data.finish_result.validation_algorithm = auto_ranged_get->validation_algorithm;
445 }
446 }
447
448 aws_s3_meta_request_unlock_synced_data(meta_request);
449 }
450 /* END CRITICAL SECTION */
451
452 if (work_remaining) {
453 *out_request = request;
454 } else {
455 AWS_ASSERT(request == NULL);
456 aws_s3_meta_request_finish(meta_request);
457 }
458
459 return work_remaining;
460 }
461
462 /* Given a request, prepare it for sending based on its description.
463 * Currently, this is actually synchronous. */
464 static struct aws_future_void *s_s3_auto_ranged_get_prepare_request(struct aws_s3_request *request) {
465 AWS_PRECONDITION(request);
466 struct aws_s3_meta_request *meta_request = request->meta_request;
467
468 /* Generate a new ranged get request based on the original message. */
469 struct aws_http_message *message = NULL;
470 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
471
472 bool success = false;
473
474 switch (request->request_tag) {
475 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT:
476 /* A head object will be a copy of the original headers but with a HEAD request method. */
477 message = aws_s3_message_util_copy_http_message_no_body_all_headers(
478 meta_request->allocator, meta_request->initial_request_message);
479 if (message) {
480 aws_http_message_set_request_method(message, g_head_method);
481 }
482 break;
483 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE:
484 message = aws_s3_ranged_get_object_message_new(
485 meta_request->allocator,
486 meta_request->initial_request_message,
487 request->part_range_start,
488 request->part_range_end);
489 break;
490 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1:
491 message = aws_s3_message_util_copy_http_message_no_body_all_headers(
492 meta_request->allocator, meta_request->initial_request_message);
493 if (message) {
494 aws_s3_message_util_set_multipart_request_path(
495 meta_request->allocator, NULL, request->part_number, false, message);
496 }
497 break;
498 }
499
500 if (message == NULL) {
501 AWS_LOGF_ERROR(
502 AWS_LS_S3_META_REQUEST,
503 "id=%p Could not create message for request with tag %d for auto-ranged-get meta request.",
504 (void *)meta_request,
505 request->request_tag);
506 goto finish;
507 }
508 if (meta_request->checksum_config.validate_response_checksum) {
509 aws_http_headers_set(aws_http_message_get_headers(message), g_request_validation_mode, g_enabled);
510 }
511 if (!auto_ranged_get->initial_message_has_if_match_header && auto_ranged_get->etag) {
512 /* Add the if_match to the request */
513 AWS_LOGF_DEBUG(
514 AWS_LS_S3_META_REQUEST,
515 "id=%p: Added the If-Match header to request %p for part %d",
516 (void *)meta_request,
517 (void *)request,
518 request->part_number);
519 aws_http_headers_set(
520 aws_http_message_get_headers(message),
521 g_if_match_header_name,
522 aws_byte_cursor_from_string(auto_ranged_get->etag));
523 }
524
525 aws_s3_request_setup_send_data(request, message);
526 aws_http_message_release(message);
527
528 /* Success! */
529 AWS_LOGF_DEBUG(
530 AWS_LS_S3_META_REQUEST,
531 "id=%p: Created request %p for part %d allocated from pool %d",
532 (void *)meta_request,
533 (void *)request,
534 request->part_number,
535 request->should_allocate_buffer_from_pool);
536
537 success = true;
538
539 finish:;
540 struct aws_future_void *future = aws_future_void_new(meta_request->allocator);
541 if (success) {
542 aws_future_void_set_result(future);
543 } else {
544 aws_future_void_set_error(future, aws_last_error_or_unknown());
545 }
546 return future;
547 }
548
549 /* Check the finish result of meta request.
550 * Return true if the request failed because it downloaded an empty file.
551 * Return false if the request failed for any other reason */
552 static bool s_check_empty_file_download_error(struct aws_s3_request *failed_request) {
553 struct aws_http_headers *failed_headers = failed_request->send_data.response_headers;
554 struct aws_byte_buf failed_body = failed_request->send_data.response_body;
555 if (failed_headers && failed_body.capacity > 0) {
556 struct aws_byte_cursor content_type;
557 AWS_ZERO_STRUCT(content_type);
558 if (!aws_http_headers_get(failed_headers, g_content_type_header_name, &content_type)) {
559 /* Content type found */
560 if (aws_byte_cursor_eq_ignore_case(&content_type, &g_application_xml_value)) {
561 /* XML response */
562 struct aws_byte_cursor xml_doc = aws_byte_cursor_from_buf(&failed_body);
563 const char *path_to_size[] = {"Error", "ActualObjectSize", NULL};
564 struct aws_byte_cursor size = {0};
565 aws_xml_get_body_at_path(failed_request->allocator, xml_doc, path_to_size, &size);
566 if (aws_byte_cursor_eq_c_str(&size, "0")) {
567 return true;
568 }
569 }
570 }
571 }
572 return false;
573 }
574
575 static int s_discover_object_range_and_size(
576 struct aws_s3_meta_request *meta_request,
577 struct aws_s3_request *request,
578 int error_code,
579 uint64_t *out_object_range_start,
580 uint64_t *out_object_range_end,
581 uint64_t *out_object_size,
582 uint64_t *out_first_part_size,
583 bool *out_empty_file_error) {
584
585 AWS_PRECONDITION(out_object_size);
586 AWS_PRECONDITION(out_object_range_start);
587 AWS_PRECONDITION(out_object_range_end);
588 AWS_PRECONDITION(out_first_part_size);
589
590 int result = AWS_OP_ERR;
591
592 uint64_t content_length = 0;
593 uint64_t object_size = 0;
594 uint64_t object_range_start = 0;
595 uint64_t object_range_end = 0;
596 uint64_t first_part_size = 0;
597
598 AWS_ASSERT(request->discovers_object_size);
599 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
600 switch (request->request_tag) {
601 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT:
602 if (error_code != AWS_ERROR_SUCCESS) {
603 /* If the head request failed, there's nothing we can do, so resurface the error code. */
604 aws_raise_error(error_code);
605 break;
606 }
607
608 /* There should be a Content-Length header that indicates the total size of the range.*/
609 if (aws_s3_parse_content_length_response_header(
610 meta_request->allocator, request->send_data.response_headers, &content_length)) {
611
612 AWS_LOGF_ERROR(
613 AWS_LS_S3_META_REQUEST,
614 "id=%p Could not find content-length header for request %p",
615 (void *)meta_request,
616 (void *)request);
617 break;
618 }
619
620 /* if the inital message had a ranged header, there should also be a Content-Range header that specifies the
621 * object range and total object size. Otherwise, the size and range should be equal to the
622 * total_content_length. */
623 if (!auto_ranged_get->initial_message_has_range_header) {
624 object_size = content_length;
625 if (content_length > 0) {
626 object_range_end = content_length - 1; /* range-end is inclusive */
627 }
628 } else if (aws_s3_parse_content_range_response_header(
629 request->send_data.response_headers, &object_range_start, &object_range_end, &object_size)) {
630
631 AWS_LOGF_ERROR(
632 AWS_LS_S3_META_REQUEST,
633 "id=%p Could not find content-range header for request %p",
634 (void *)meta_request,
635 (void *)request);
636 break;
637 }
638
639 result = AWS_OP_SUCCESS;
640 break;
641 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1:
642 AWS_ASSERT(request->part_number == 1);
643 AWS_ASSERT(request->send_data.response_headers != NULL);
644 /* There should be a Content-Length header that indicates the size of first part. */
645 if (aws_s3_parse_content_length_response_header(
646 meta_request->allocator, request->send_data.response_headers, &content_length)) {
647
648 AWS_LOGF_ERROR(
649 AWS_LS_S3_META_REQUEST,
650 "id=%p Could not find content-length header for request %p",
651 (void *)meta_request,
652 (void *)request);
653 break;
654 }
655 first_part_size = content_length;
656
657 if (first_part_size > 0) {
658 /* Parse the object size from the part response. */
659 if (aws_s3_parse_content_range_response_header(
660 request->send_data.response_headers, NULL, NULL, &object_size)) {
661
662 AWS_LOGF_ERROR(
663 AWS_LS_S3_META_REQUEST,
664 "id=%p Could not find content-range header for request %p",
665 (void *)meta_request,
666 (void *)request);
667 break;
668 }
669 /* When discovering the object size via GET_OBJECT_WITH_PART_NUMBER_1, the object range is the entire
670 * object. */
671 object_range_start = 0;
672 object_range_end = object_size - 1; /* range-end is inclusive */
673 }
674
675 result = AWS_OP_SUCCESS;
676 break;
677 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE:
678 AWS_ASSERT(request->part_number == 1);
679
680 if (error_code != AWS_ERROR_SUCCESS) {
681 /* If we hit an empty file while trying to discover the object-size via part, then this request
682 failure
683 * is as designed. */
684 if (!auto_ranged_get->initial_message_has_range_header && s_check_empty_file_download_error(request)) {
685 AWS_LOGF_DEBUG(
686 AWS_LS_S3_META_REQUEST,
687 "id=%p Detected empty file with request %p. Sending new request without range header.",
688 (void *)meta_request,
689 (void *)request);
690
691 object_size = 0ULL;
692 *out_empty_file_error = true;
693 result = AWS_OP_SUCCESS;
694 } else {
695 /* Otherwise, resurface the error code. */
696 aws_raise_error(error_code);
697 }
698 break;
699 }
700
701 AWS_ASSERT(request->send_data.response_headers != NULL);
702
703 /* Parse the object size from the part response. */
704 if (aws_s3_parse_content_range_response_header(
705 request->send_data.response_headers, &object_range_start, &object_range_end, &object_size)) {
706
707 AWS_LOGF_ERROR(
708 AWS_LS_S3_META_REQUEST,
709 "id=%p Could not find content-range header for request %p",
710 (void *)meta_request,
711 (void *)request);
712
713 break;
714 }
715 if (auto_ranged_get->initial_message_has_range_header) {
716 if (auto_ranged_get->initial_message_has_end_range) {
717 object_range_end = aws_min_u64(object_size - 1, auto_ranged_get->initial_range_end);
718 } else {
719 object_range_end = object_size - 1;
720 }
721 } else {
722 /* When discovering the object size via GET_OBJECT_WITH_RANGE, the object range is the entire object. */
723 object_range_start = 0;
724 object_range_end = object_size - 1; /* range-end is inclusive */
725 }
726 result = AWS_OP_SUCCESS;
727 break;
728 default:
729 AWS_ASSERT(false);
730 break;
731 }
732
733 if (result == AWS_OP_SUCCESS) {
734 *out_object_size = object_size;
735 *out_object_range_start = object_range_start;
736 *out_object_range_end = object_range_end;
737 *out_first_part_size = first_part_size;
738 }
739
740 return result;
741 }
742
743 static void s_s3_auto_ranged_get_request_finished(
744 struct aws_s3_meta_request *meta_request,
745 struct aws_s3_request *request,
746 int error_code) {
747 AWS_PRECONDITION(meta_request);
748 AWS_PRECONDITION(meta_request->impl);
749 AWS_PRECONDITION(request);
750
751 struct aws_s3_auto_ranged_get *auto_ranged_get = meta_request->impl;
752 AWS_PRECONDITION(auto_ranged_get);
753
754 uint64_t object_range_start = 0ULL;
755 uint64_t object_range_end = 0ULL;
756 uint64_t object_size = 0ULL;
757 uint64_t first_part_size = 0ULL;
758
759 bool found_object_size = false;
760 bool request_failed = error_code != AWS_ERROR_SUCCESS;
761 bool first_part_buffer_size_mismatch =
762 (error_code == AWS_ERROR_S3_INTERNAL_BUFFER_SIZE_MISMATCH_RETRYING_WITH_RANGE);
763 bool empty_file_error = false;
764
765 if (request->discovers_object_size) {
766 /* Try to discover the object-range and object-size.*/
767 if (s_discover_object_range_and_size(
768 meta_request,
769 request,
770 error_code,
771 &object_range_start,
772 &object_range_end,
773 &object_size,
774 &first_part_size,
775 &empty_file_error)) {
776
777 error_code = aws_last_error_or_unknown();
778
779 goto update_synced_data;
780 }
781 /* Always extract ETag header for part size estimation */
782 if (!request_failed || first_part_buffer_size_mismatch) {
783 struct aws_byte_cursor etag_header_value;
784 AWS_ASSERT(auto_ranged_get->etag == NULL);
785 if (aws_http_headers_get(request->send_data.response_headers, g_etag_header_name, &etag_header_value) ==
786 AWS_OP_SUCCESS) {
787 AWS_LOGF_TRACE(
788 AWS_LS_S3_META_REQUEST,
789 "id=%p ETag received for the meta request. value is: " PRInSTR "",
790 (void *)meta_request,
791 AWS_BYTE_CURSOR_PRI(etag_header_value));
792
793 if (!auto_ranged_get->initial_message_has_if_match_header) {
794 /* Store ETag if needed for If-Match header */
795 auto_ranged_get->etag =
796 aws_string_new_from_cursor(auto_ranged_get->base.allocator, &etag_header_value);
797 }
798 } else {
799 AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "id=%p ETag headers are missing", (void *)meta_request);
800 aws_raise_error(AWS_ERROR_S3_MISSING_ETAG);
801 error_code = AWS_ERROR_S3_MISSING_ETAG;
802 goto update_synced_data;
803 }
804 /* Extract number of parts stored in S3 from ETag and calculate estimated part size */
805 uint32_t num_parts = 0;
806 if (aws_s3_extract_parts_from_etag(etag_header_value, &num_parts) == AWS_OP_SUCCESS && num_parts > 0) {
807 auto_ranged_get->estimated_object_stored_part_size = object_size / num_parts;
808
809 AWS_LOGF_DEBUG(
810 AWS_LS_S3_META_REQUEST,
811 "id=%p Estimated object stored part size: object_size=%" PRIu64 ", num_parts=%" PRIu32
812 ", estimated_part_size=%" PRIu64,
813 (void *)meta_request,
814 object_size,
815 num_parts,
816 auto_ranged_get->estimated_object_stored_part_size);
817 } else {
818 num_parts = 1;
819 /* Failed to parse ETags */
820 AWS_LOGF_WARN(
821 AWS_LS_S3_META_REQUEST,
822 "id=%p Failed to parse ETags, fallback to default part size.",
823 (void *)meta_request);
824 auto_ranged_get->estimated_object_stored_part_size = g_default_part_size_fallback;
825 goto update_synced_data;
826 }
827 auto_ranged_get->num_stored_parts = num_parts;
828 }
829
830 /* If we were able to discover the object-range/content length successfully, then any error code that was passed
831 * into this function is being handled and does not indicate an overall failure.*/
832 error_code = AWS_ERROR_SUCCESS;
833 found_object_size = true;
834 uint32_t max_connections = aws_s3_client_get_max_active_connections(meta_request->client, meta_request);
835
836 if (auto_ranged_get->force_dynamic_part_size ||
837 (!auto_ranged_get->part_size_set && !meta_request->client->part_size_set)) {
838 /* No part size has been set from user. Now we use the optimal part size based on the throughput and memory
839 * limit */
840 uint64_t out_request_optimal_range_size = 0;
841
842 if (aws_s3_calculate_request_optimal_range_size(
843 meta_request->client->optimal_range_size,
844 auto_ranged_get->estimated_object_stored_part_size,
845 meta_request->is_express,
846 &out_request_optimal_range_size) == AWS_OP_SUCCESS) {
847 /* Apply a buffer pool alignment to the calculated result. */
848 out_request_optimal_range_size = aws_s3_buffer_pool_derive_aligned_buffer_size(
849 meta_request->client->buffer_pool, out_request_optimal_range_size);
850 /* For O_DIRECT download, also ensure page alignment.
851 * Buffer pool typically aligns to chunk_size which is page-aligned, but apply
852 * a defensive round-up here to guarantee the invariant. */
853 if (meta_request->recv_file_direct_io) {
854 size_t page_size = aws_system_info_page_size();
855 if (out_request_optimal_range_size % page_size != 0) {
856 out_request_optimal_range_size = ((out_request_optimal_range_size / page_size) + 1) * page_size;
857 }
858 }
859 AWS_LOGF_INFO(
860 AWS_LS_S3_META_REQUEST,
861 "id=%p: Override the part size to be optimal. part_size=%" PRIu64 ".",
862 (void *)meta_request,
863 out_request_optimal_range_size);
864 /* Override the part size to be optimal */
865 *((size_t *)&meta_request->part_size) = (size_t)out_request_optimal_range_size;
866 uint64_t parts_threshold = aws_mul_u64_saturating(max_connections, 2);
867 if (auto_ranged_get->num_stored_parts > parts_threshold) {
868 /* If the number of parts is greater than the threshold, so that we will be reusing the buffers
869 * enough from the buffer pool. Let's add a special block for the buffer pool to optimize the
870 * case.*/
871 AWS_LOGF_INFO(
872 AWS_LS_S3_META_REQUEST,
873 "id=%p: Apply buffer pool optimization for the size=%zu.",
874 (void *)meta_request,
875 meta_request->part_size);
876 aws_s3_buffer_pool_add_special_size(meta_request->client->buffer_pool, meta_request->part_size);
877 meta_request->buffer_pool_optimized = true;
878 }
879 if (request->request_tag == AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT) {
880 /* Update the first part size as well, if we haven't made the request yet. */
881 first_part_size = meta_request->part_size;
882 }
883 }
884 }
885
886 /* Check for checksums if requested to */
887 if (meta_request->checksum_config.validate_response_checksum) {
888 if (aws_s3_check_headers_for_checksum(
889 meta_request,
890 request->send_data.response_headers,
891 &meta_request->meta_request_level_running_response_sum,
892 &meta_request->meta_request_level_response_header_checksum,
893 true) != AWS_OP_SUCCESS) {
894 error_code = aws_last_error_or_unknown();
895 goto update_synced_data;
896 }
897 }
898
899 if (meta_request->is_express &&
900 meta_request->part_size < g_s3express_connection_limitation_part_size_threshold &&
901 object_size > g_s3express_connection_limitation_object_size_threshold) {
902 /**
903 * TODO: THIS IS A TEMP WORKAROUND, not the long term solution.
904 * 1. If the Part Size we set is larger than the possible size to hit the limitation, we are safe to
905 * make as many connections as we want.
906 * 2. If the object size is less than the threshold, we keep our previous behavior, as it's less likely
907 * to hit the server side limitation.
908 *
909 * Otherwise, we need to make sure the number of concurrent connections is lower than the limitation.
910 */
911 uint32_t max_active_connections_override = aws_min_u32(g_s3express_connection_limitation, max_connections);
912 if (max_active_connections_override < max_connections) {
913 /* Override the max active connections to be the limitation. */
914 *((uint32_t *)&meta_request->max_active_connections_override) =
915 (uint32_t)max_active_connections_override;
916 AWS_LOGF_WARN(
917 AWS_LS_S3_META_REQUEST,
918 "id=%p: Override the max active connections for the meta request to be the limitation: %d",
919 (void *)meta_request,
920 max_active_connections_override);
921 }
922 }
923
924 if (!empty_file_error && meta_request->headers_callback != NULL) {
925 /* Modify the header received to fake the header for the whole meta request. */
926 if (request->request_tag == AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE ||
927 request->request_tag == AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1) {
928
929 if (auto_ranged_get->initial_message_has_range_header) {
930 /* Populate the header with object_range */
931 char content_range_buffer[64] = "";
932 snprintf(
933 content_range_buffer,
934 sizeof(content_range_buffer),
935 "bytes %" PRIu64 "-%" PRIu64 "/%" PRIu64,
936 object_range_start,
937 object_range_end,
938 object_size);
939 aws_http_headers_set(
940 request->send_data.response_headers,
941 g_content_range_header_name,
942 aws_byte_cursor_from_c_str(content_range_buffer));
943 } else {
944 /* content range isn't applicable. */
945 aws_http_headers_erase(request->send_data.response_headers, g_content_range_header_name);
946 }
947 }
948
949 uint64_t content_length = object_size ? object_range_end - object_range_start + 1 : 0;
950 char content_length_buffer[64] = "";
951 snprintf(content_length_buffer, sizeof(content_length_buffer), "%" PRIu64, content_length);
952 aws_http_headers_set(
953 request->send_data.response_headers,
954 g_content_length_header_name,
955 aws_byte_cursor_from_c_str(content_length_buffer));
956
957 if (meta_request->headers_callback(
958 meta_request,
959 request->send_data.response_headers,
960 s_s3_auto_ranged_get_success_status(meta_request),
961 meta_request->user_data)) {
962
963 error_code = aws_last_error_or_unknown();
964 }
965 meta_request->headers_callback = NULL;
966 }
967 }
968
969 update_synced_data:
970
971 /* BEGIN CRITICAL SECTION */
972 {
973 aws_s3_meta_request_lock_synced_data(meta_request);
974 bool finishing_metrics = true;
975
976 /* If the object range was found, then record it. */
977 if (found_object_size) {
978 AWS_ASSERT(!auto_ranged_get->synced_data.object_range_known);
979 auto_ranged_get->synced_data.object_range_known = true;
980 auto_ranged_get->synced_data.object_range_empty = (object_size == 0);
981 auto_ranged_get->synced_data.object_range_start = object_range_start;
982 auto_ranged_get->synced_data.object_range_end = object_range_end;
983 if (!first_part_buffer_size_mismatch && first_part_size) {
984 /* Only record the discovered first-part size on a successful partNumber request.
985 * On a buffer-size mismatch the request was cancelled before the body arrived, so
986 * we fall back to ranged gets using the client part_size (already the default). */
987 auto_ranged_get->synced_data.first_part_size = first_part_size;
988 }
989 if (auto_ranged_get->synced_data.object_range_empty == 0) {
990 auto_ranged_get->synced_data.total_num_parts = aws_s3_calculate_auto_ranged_get_num_parts(
991 meta_request->part_size,
992 auto_ranged_get->synced_data.first_part_size,
993 object_range_start,
994 object_range_end);
995 }
996 }
997
998 switch (request->request_tag) {
999 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_HEAD_OBJECT:
1000 auto_ranged_get->synced_data.head_object_completed = true;
1001 AWS_LOGF_DEBUG(AWS_LS_S3_META_REQUEST, "id=%p Head object completed.", (void *)meta_request);
1002 break;
1003 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_PART_NUMBER_1:
1004 AWS_LOGF_DEBUG(AWS_LS_S3_META_REQUEST, "id=%p Get Part Number completed.", (void *)meta_request);
1005 if (first_part_buffer_size_mismatch && found_object_size) {
1006 /* The hint-sized buffer was too small to hold the first part, so the partNumber
1007 * request was cancelled before its body arrived. We already parsed the object size
1008 * from the cancelled response's headers, so we keep that discovered range and fetch
1009 * the data as ranged gets using the client part_size. Note: the recovery ranged gets
1010 * may not align to stored part boundaries, so per-part checksum validation may not
1011 * be possible in this case. */
1012 auto_ranged_get->synced_data.num_parts_requested = 0;
1013 break;
1014 }
1015 /* fall through */
1016 case AWS_S3_AUTO_RANGE_GET_REQUEST_TYPE_GET_OBJECT_WITH_RANGE:
1017 if (empty_file_error) {
1018 /*
1019 * Try to download the object again using GET_OBJECT_WITH_PART_NUMBER_1. If the file is still
1020 * empty, successful response headers will be provided to users. If not, the newer version of
1021 * the file will be downloaded.
1022 */
1023 auto_ranged_get->synced_data.num_parts_requested = 0;
1024 auto_ranged_get->synced_data.object_range_known = 0;
1025 break;
1026 }
1027
1028 ++auto_ranged_get->synced_data.num_parts_completed;
1029
1030 if (!request_failed) {
1031
1032 /* Record the number of parts that checksum has been validated */
1033 if (request->did_validate) {
1034 if (auto_ranged_get->validation_algorithm == AWS_SCA_NONE) {
1035 auto_ranged_get->validation_algorithm = request->validation_algorithm;
1036 }
1037 /* They should be the same. */
1038 AWS_ASSERT(auto_ranged_get->validation_algorithm == request->validation_algorithm);
1039 ++auto_ranged_get->synced_data.num_parts_checksum_validated;
1040 }
1041 ++auto_ranged_get->synced_data.num_parts_successful;
1042
1043 /* Send progress_callback for delivery on io_event_loop thread */
1044 if (meta_request->progress_callback != NULL) {
1045 struct aws_s3_meta_request_event event = {.type = AWS_S3_META_REQUEST_EVENT_PROGRESS};
1046 event.u.progress.info.bytes_transferred = request->send_data.response_body.len;
1047 if (auto_ranged_get->synced_data.object_range_empty) {
1048 event.u.progress.info.content_length = 0;
1049 } else {
1050 /* Note that range-end is inclusive */
1051 event.u.progress.info.content_length = auto_ranged_get->synced_data.object_range_end + 1 -
1052 auto_ranged_get->synced_data.object_range_start;
1053 }
1054 aws_s3_meta_request_add_event_for_delivery_synced(meta_request, &event);
1055 }
1056
1057 aws_s3_meta_request_stream_response_body_synced(meta_request, request);
1058 /* The body of the request is queued to be streamed, don't finish the metrics yet. */
1059 finishing_metrics = false;
1060
1061 AWS_LOGF_DEBUG(
1062 AWS_LS_S3_META_REQUEST,
1063 "id=%p: %d out of %d parts have completed.",
1064 (void *)meta_request,
1065 (auto_ranged_get->synced_data.num_parts_successful +
1066 auto_ranged_get->synced_data.num_parts_failed),
1067 auto_ranged_get->synced_data.total_num_parts);
1068 } else {
1069 ++auto_ranged_get->synced_data.num_parts_failed;
1070 }
1071 break;
1072 }
1073
1074 if (error_code != AWS_ERROR_SUCCESS) {
1075 if (error_code == AWS_ERROR_S3_INVALID_RESPONSE_STATUS &&
1076 request->send_data.response_status == AWS_HTTP_STATUS_CODE_412_PRECONDITION_FAILED &&
1077 !auto_ranged_get->initial_message_has_if_match_header) {
1078 /* Use more clear error code as we added the if-match header under the hood. */
1079 error_code = AWS_ERROR_S3_OBJECT_MODIFIED;
1080 }
1081 aws_s3_meta_request_set_fail_synced(meta_request, request, error_code);
1082 if (error_code == AWS_ERROR_S3_RESPONSE_CHECKSUM_MISMATCH) {
1083 /* It's a mismatch of checksum, tell user that we validated the checksum and the algorithm we
1084 * validated
1085 */
1086 meta_request->synced_data.finish_result.did_validate = true;
1087 meta_request->synced_data.finish_result.validation_algorithm = request->validation_algorithm;
1088 }
1089 }
1090 if (finishing_metrics) {
1091 aws_s3_request_finish_up_metrics_synced(request, meta_request);
1092 }
1093 aws_s3_meta_request_unlock_synced_data(meta_request);
1094 }
1095 /* END CRITICAL SECTION */
1096 }