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

s3_request: fix broken requests_in_flight counter #216

Merged
merged 7 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/aws/s3/private/s3_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ void aws_s3_client_notify_connection_finished(
int error_code,
enum aws_s3_connection_finish_code finish_code);

void aws_s3_client_notify_request_destroyed(struct aws_s3_client *client, struct aws_s3_request *request);

AWS_EXTERN_C_BEGIN

AWS_S3_API
Expand Down
40 changes: 22 additions & 18 deletions source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,25 @@ void aws_s3_client_update_meta_requests_threaded(struct aws_s3_client *client) {
}
}

static void s_s3_client_meta_request_finished_request(
struct aws_s3_client *client,
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
int error_code) {
AWS_PRECONDITION(client);
AWS_PRECONDITION(request);

if (request->tracked_by_client) {
/* BEGIN CRITICAL SECTION */
aws_s3_client_lock_synced_data(client);
aws_atomic_fetch_sub(&client->stats.num_requests_in_flight, 1);
s_s3_client_schedule_process_work_synced(client);
aws_s3_client_unlock_synced_data(client);
/* END CRITICAL SECTION */
}
aws_s3_meta_request_finished_request(meta_request, request, error_code);
}

static void s_s3_client_prepare_callback_queue_request(
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
Expand All @@ -1380,7 +1399,7 @@ static void s_s3_client_prepare_callback_queue_request(
AWS_PRECONDITION(client);

if (error_code != AWS_ERROR_SUCCESS) {
aws_s3_meta_request_finished_request(meta_request, request, error_code);
s_s3_client_meta_request_finished_request(client, meta_request, request, error_code);

aws_s3_request_release(request);
request = NULL;
Expand Down Expand Up @@ -1419,7 +1438,7 @@ void aws_s3_client_update_connections_threaded(struct aws_s3_client *client) {
/* Unless the request is marked "always send", if this meta request has a finish result, then finish the request
* now and release it. */
if (!request->always_send && aws_s3_meta_request_has_finish_result(request->meta_request)) {
aws_s3_meta_request_finished_request(request->meta_request, request, AWS_ERROR_S3_CANCELED);
s_s3_client_meta_request_finished_request(client, request->meta_request, request, AWS_ERROR_S3_CANCELED);

aws_s3_request_release(request);
request = NULL;
Expand Down Expand Up @@ -1734,7 +1753,7 @@ void aws_s3_client_notify_connection_finished(

aws_atomic_fetch_sub(&client->stats.num_requests_network_io[meta_request->type], 1);

aws_s3_meta_request_finished_request(meta_request, request, error_code);
s_s3_client_meta_request_finished_request(client, meta_request, request, error_code);

if (connection->http_connection != NULL) {
AWS_ASSERT(endpoint->http_connection_manager);
Expand Down Expand Up @@ -1855,18 +1874,3 @@ static void s_s3_client_prepare_request_callback_retry_request(
aws_s3_client_notify_connection_finished(client, connection, error_code, AWS_S3_CONNECTION_FINISH_CODE_FAILED);
}
}

/* Called by aws_s3_request when it has finished being destroyed */
void aws_s3_client_notify_request_destroyed(struct aws_s3_client *client, struct aws_s3_request *request) {
AWS_PRECONDITION(client);
AWS_PRECONDITION(request);

if (request->tracked_by_client) {
/* BEGIN CRITICAL SECTION */
aws_s3_client_lock_synced_data(client);
aws_atomic_fetch_sub(&client->stats.num_requests_in_flight, 1);
s_s3_client_schedule_process_work_synced(client);
aws_s3_client_unlock_synced_data(client);
/* END CRITICAL SECTION */
}
}
12 changes: 1 addition & 11 deletions source/s3_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,8 @@ static void s_s3_request_destroy(void *user_data) {
return;
}

struct aws_s3_meta_request *meta_request = request->meta_request;

if (meta_request != NULL) {
struct aws_s3_client *client = meta_request->client;

if (client != NULL) {
aws_s3_client_notify_request_destroyed(client, request);
}
}

aws_s3_request_clean_up_send_data(request);
aws_byte_buf_clean_up(&request->request_body);
aws_s3_meta_request_release(request->meta_request);
aws_mem_release(request->allocator, request);
aws_s3_meta_request_release(meta_request);
}