From 06d58b81beb8586896516a2d20a93fc0ab1b3997 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 10 Feb 2025 15:02:48 -0800 Subject: [PATCH 01/40] setup ci test for dispatch queue --- .github/workflows/ci.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aa03470b..ca98637aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -205,6 +205,11 @@ jobs: macos: runs-on: macos-14 # latest + strategy: + fail-fast: false + matrix: + eventloop: ["kqueue", "dispatch_queue"] + sanitizers: [",thread", ",address,undefined"] steps: - uses: aws-actions/configure-aws-credentials@v4 with: @@ -214,7 +219,7 @@ jobs: run: | python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')" chmod a+x builder - ./builder build -p ${{ env.PACKAGE_NAME }} + ./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} --cmake-extra=-DENABLE_SANITIZERS=ON --cmake-extra=-DSANITIZERS="${{ matrix.sanitizers }}" macos-x64: runs-on: macos-14-large # latest @@ -245,6 +250,11 @@ jobs: localhost-test-macos: runs-on: macos-14 # latest + strategy: + fail-fast: false + matrix: + eventloop: ["kqueue", "dispatch_queue"] + sanitizers: [",thread", ",address,undefined"] steps: - uses: aws-actions/configure-aws-credentials@v4 with: @@ -257,7 +267,7 @@ jobs: python3 -m venv .venv source .venv/bin/activate python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')" - python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --config Debug + python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} --cmake-extra=-DENABLE_SANITIZERS=ON --cmake-extra=-DSANITIZERS="${{ matrix.sanitizers }}" --config Debug localhost-test-win: runs-on: windows-2022 # latest From 347901209d6e1aeea5850eb40cb27e6533e861eb Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 11 Feb 2025 14:18:28 -0800 Subject: [PATCH 02/40] kick ci From e86a7cbcaef8d2cc94be0e691d4f753abe639fdc Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 12 Feb 2025 09:38:38 -0800 Subject: [PATCH 03/40] WIP: test async listen --- source/connection.c | 81 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/source/connection.c b/source/connection.c index a53aebe19..7a2ff53b4 100644 --- a/source/connection.c +++ b/source/connection.c @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -431,6 +432,15 @@ void aws_http_connection_release(struct aws_http_connection *connection) { } } +struct aws_server_user_data { + struct aws_allocator *alloc; + struct aws_http_server *server; + struct aws_mutex mutex; + struct aws_condition_variable condition_variable; + int setup_error_code; + bool setup_complete; +}; + /* At this point, the server bootstrapper has accepted an incoming connection from a client and set up a channel. * Now we need to create an aws_http_connection and insert it into the channel as a channel-handler. * Note: Be careful not to access server->socket until lock is acquired to avoid race conditions */ @@ -442,7 +452,8 @@ static void s_server_bootstrap_on_accept_channel_setup( (void)bootstrap; AWS_ASSERT(user_data); - struct aws_http_server *server = user_data; + struct aws_server_user_data *server_user_data = user_data; + struct aws_http_server *server = server_user_data->server; bool user_cb_invoked = false; struct aws_http_connection *connection = NULL; if (error_code) { @@ -588,7 +599,8 @@ static void s_server_bootstrap_on_accept_channel_shutdown( (void)bootstrap; AWS_ASSERT(user_data); - struct aws_http_server *server = user_data; + struct aws_server_user_data *server_user_data = user_data; + struct aws_http_server *server = server_user_data->server; /* Figure out which connection this was, and remove that entry from the map. * It won't be in the map if something went wrong while setting up the connection. */ @@ -617,8 +629,30 @@ static void s_server_bootstrap_on_accept_channel_shutdown( static void s_server_bootstrap_on_server_listener_destroy(struct aws_server_bootstrap *bootstrap, void *user_data) { (void)bootstrap; AWS_ASSERT(user_data); - struct aws_http_server *server = user_data; + struct aws_server_user_data *server_user_data = user_data; + struct aws_http_server *server = server_user_data->server; s_http_server_clean_up(server); + aws_mem_release(server_user_data->alloc, server_user_data); +} + +static bool s_listener_connected_predicate(void *user_data) { + struct aws_server_user_data *setup_test_args = (struct aws_server_user_data *)user_data; + bool finished = setup_test_args->setup_complete; + return finished; +} + +/* the server listener has finished setup. We released the socket if error_code is not 0. */ +static void s_server_bootstrap_on_server_listener_setup( + struct aws_server_bootstrap *bootstrap, + int error_code, + void *user_data) { + (void)bootstrap; + struct aws_server_user_data *server_user_data = user_data; + aws_mutex_lock(&server_user_data->mutex); + server_user_data->setup_error_code = error_code; + server_user_data->setup_complete = true; + aws_condition_variable_notify_one(&server_user_data->condition_variable); + aws_mutex_unlock(&server_user_data->mutex); } struct aws_http_server *aws_http_server_new(const struct aws_http_server_options *options) { @@ -672,6 +706,14 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options server->is_using_tls = true; } + struct aws_server_user_data *server_user_data = + aws_mem_calloc(options->allocator, 1, sizeof(struct aws_server_user_data)); + server_user_data->server = server; + server_user_data->alloc = options->allocator; + aws_mutex_init(&server_user_data->mutex); + aws_condition_variable_init(&server_user_data->condition_variable); + server_user_data->setup_complete = false; + struct aws_server_socket_channel_bootstrap_options bootstrap_options = { .enable_read_back_pressure = options->manual_window_management, .tls_options = options->tls_options, @@ -680,21 +722,44 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options .incoming_callback = s_server_bootstrap_on_accept_channel_setup, .shutdown_callback = s_server_bootstrap_on_accept_channel_shutdown, .destroy_callback = s_server_bootstrap_on_server_listener_destroy, + .setup_callback = s_server_bootstrap_on_server_listener_setup, .host_name = options->endpoint->address, .port = options->endpoint->port, - .user_data = server, + .user_data = server_user_data, }; - server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); + int listen_error = AWS_OP_SUCCESS; + // DEBUG + if (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK || + (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT && + AWS_USE_APPLE_NETWORK_FRAMEWORK)) { + /* + * WARNING!!!! + * For Apple Network Framework, socket listen is an async function, we would need block here waiting for + * setup complete. + */ + server->socket = aws_server_bootstrap_new_socket_listener_async(&bootstrap_options); + aws_mutex_lock(&server_user_data->mutex); + aws_condition_variable_wait_pred( + &server_user_data->condition_variable, + &server_user_data->mutex, + s_listener_connected_predicate, + server_user_data); + aws_mutex_unlock(&server_user_data->mutex); + listen_error = server_user_data->setup_error_code; + } else { + server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); + listen_error = aws_last_error(); + } s_server_unlock_synced_data(server); - if (!server->socket) { + if (!server->socket || listen_error) { AWS_LOGF_ERROR( AWS_LS_HTTP_SERVER, "static: Failed creating new socket listener, error %d (%s). Cannot create server.", - aws_last_error(), - aws_error_name(aws_last_error())); + listen_error, + aws_error_name(listen_error)); goto socket_error; } From bd7fb0f13e4fef6774b6673d34fd5be3c7350fe0 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 12 Feb 2025 09:49:10 -0800 Subject: [PATCH 04/40] use async listen for apple --- source/connection.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/connection.c b/source/connection.c index 7a2ff53b4..f94326c2e 100644 --- a/source/connection.c +++ b/source/connection.c @@ -729,10 +729,15 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options }; int listen_error = AWS_OP_SUCCESS; - // DEBUG +#if (defined(AWS_ENABLE_DISPATCH_QUEUE) && !defined(AWS_ENABLE_KQUEUE)) || defined(AWS_USE_APPLE_NETWORK_FRAMEWORK) +# define AWS_NETWORK_FRAMEWORK_ENABLED 1 +#else +# define AWS_NETWORK_FRAMEWORK_ENABLED 0 +#endif + if (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK || - (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT && - AWS_USE_APPLE_NETWORK_FRAMEWORK)) { + (AWS_NETWORK_FRAMEWORK_ENABLED && + bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT)) { /* * WARNING!!!! * For Apple Network Framework, socket listen is an async function, we would need block here waiting for From c4252cfc417416a2906c48380134b74e651df11e Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 12 Feb 2025 10:06:10 -0800 Subject: [PATCH 05/40] use platform default socket impl --- source/connection.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/source/connection.c b/source/connection.c index f94326c2e..299fe8465 100644 --- a/source/connection.c +++ b/source/connection.c @@ -11,6 +11,8 @@ #include +#include + #include #include #include @@ -729,15 +731,9 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options }; int listen_error = AWS_OP_SUCCESS; -#if (defined(AWS_ENABLE_DISPATCH_QUEUE) && !defined(AWS_ENABLE_KQUEUE)) || defined(AWS_USE_APPLE_NETWORK_FRAMEWORK) -# define AWS_NETWORK_FRAMEWORK_ENABLED 1 -#else -# define AWS_NETWORK_FRAMEWORK_ENABLED 0 -#endif - if (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK || - (AWS_NETWORK_FRAMEWORK_ENABLED && - bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT)) { + (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT && + aws_socket_get_default_impl_type() == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK)) { /* * WARNING!!!! * For Apple Network Framework, socket listen is an async function, we would need block here waiting for From 8c97197ee94ea8975dc44db08bf30ab9df3a444e Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 12 Feb 2025 10:18:18 -0800 Subject: [PATCH 06/40] improve error handle --- source/connection.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/connection.c b/source/connection.c index 299fe8465..25d2b998a 100644 --- a/source/connection.c +++ b/source/connection.c @@ -11,8 +11,6 @@ #include -#include - #include #include #include @@ -731,9 +729,15 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options }; int listen_error = AWS_OP_SUCCESS; +#if (defined(AWS_ENABLE_DISPATCH_QUEUE) && !defined(AWS_ENABLE_KQUEUE)) || defined(AWS_USE_APPLE_NETWORK_FRAMEWORK) +# define AWS_NETWORK_FRAMEWORK_ENABLED 1 +#else +# define AWS_NETWORK_FRAMEWORK_ENABLED 0 +#endif + if (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK || - (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT && - aws_socket_get_default_impl_type() == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK)) { + (AWS_NETWORK_FRAMEWORK_ENABLED && + bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT)) { /* * WARNING!!!! * For Apple Network Framework, socket listen is an async function, we would need block here waiting for @@ -750,12 +754,14 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options listen_error = server_user_data->setup_error_code; } else { server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); - listen_error = aws_last_error(); + if (!server->socket) { + listen_error = aws_last_error(); + } } s_server_unlock_synced_data(server); - if (!server->socket || listen_error) { + if (listen_error) { AWS_LOGF_ERROR( AWS_LS_HTTP_SERVER, "static: Failed creating new socket listener, error %d (%s). Cannot create server.", From 91232371555f2d8e01e9876b91758b3d7ef3ee8f Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 12 Feb 2025 10:22:46 -0800 Subject: [PATCH 07/40] disable sanitizer --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca98637aa..7b1a0af37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -209,7 +209,6 @@ jobs: fail-fast: false matrix: eventloop: ["kqueue", "dispatch_queue"] - sanitizers: [",thread", ",address,undefined"] steps: - uses: aws-actions/configure-aws-credentials@v4 with: @@ -219,7 +218,7 @@ jobs: run: | python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')" chmod a+x builder - ./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} --cmake-extra=-DENABLE_SANITIZERS=ON --cmake-extra=-DSANITIZERS="${{ matrix.sanitizers }}" + ./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} macos-x64: runs-on: macos-14-large # latest @@ -254,7 +253,6 @@ jobs: fail-fast: false matrix: eventloop: ["kqueue", "dispatch_queue"] - sanitizers: [",thread", ",address,undefined"] steps: - uses: aws-actions/configure-aws-credentials@v4 with: @@ -267,7 +265,7 @@ jobs: python3 -m venv .venv source .venv/bin/activate python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')" - python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} --cmake-extra=-DENABLE_SANITIZERS=ON --cmake-extra=-DSANITIZERS="${{ matrix.sanitizers }}" --config Debug + python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} --config Debug localhost-test-win: runs-on: windows-2022 # latest From b6df45bd73c335708e8ea53d1a59f826b7097728 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 21 Feb 2025 11:44:29 -0800 Subject: [PATCH 08/40] test with a http site --- tests/test_tls.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index 22b92e8d0..dbc0285cc 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -177,11 +177,11 @@ static int s_test_tls_download_medium_file_general( http_options.allocator = test.alloc; http_options.bootstrap = test.client_bootstrap; http_options.host_name = *aws_uri_host_name(&uri); - http_options.port = 443; + http_options.port = 80; http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; - http_options.tls_options = &tls_connection_options; + //http_options.tls_options = &tls_connection_options; http_options.user_data = &test; ASSERT_SUCCESS(aws_http_client_connect(&http_options)); @@ -219,7 +219,7 @@ static int s_test_tls_download_medium_file_general( /* wait for the request to complete */ s_test_wait(&test, s_stream_wait_pred); - ASSERT_INT_EQUALS(14428801, test.body_size); + ASSERT_INT_EQUALS(181251, test.body_size); aws_http_message_destroy(request); aws_http_stream_release(test.stream); @@ -238,7 +238,7 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("stspn.com/"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } From 92cd41130350b9faf1b4efc0414518fb75adef62 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 21 Feb 2025 11:57:45 -0800 Subject: [PATCH 09/40] add evil print all decoded data --- source/h1_connection.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/h1_connection.c b/source/h1_connection.c index b3addef50..747b247ef 100644 --- a/source/h1_connection.c +++ b/source/h1_connection.c @@ -1386,7 +1386,11 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished, } AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, "id=%p: Incoming body: %zu bytes received.", (void *)&incoming_stream->base, data->len); + AWS_LS_HTTP_STREAM, + "id=%p: Incoming body: %zu bytes received: " PRInSTR, + (void *)&incoming_stream->base, + data->len, + AWS_BYTE_CURSOR_PRI(*data)); if (connection->base.stream_manual_window_management) { /* Let stream window shrink by amount of body data received */ From 60e7cdb9211b79e035b6a58744425d1df5cdb3e6 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 21 Feb 2025 13:44:32 -0800 Subject: [PATCH 10/40] more prints for the error line --- source/h1_decoder.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/h1_decoder.c b/source/h1_decoder.c index c615d09a6..ae7a65d07 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -98,6 +98,15 @@ static int s_state_getline(struct aws_h1_decoder *decoder, struct aws_byte_curso size_t line_length = 0; bool found_crlf = s_scan_for_crlf(decoder, *input, &line_length); + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: Found CRLF: %d, has_prev_data: %d, line_length: %zu, data is " PRInSTR, + decoder->logging_id, + found_crlf, + has_prev_data, + line_length, + AWS_BYTE_CURSOR_PRI(*input)); + /* Found end of line! Run the line processor on it */ struct aws_byte_cursor line = aws_byte_cursor_advance(input, line_length); @@ -254,7 +263,11 @@ static int s_linestate_chunk_terminator(struct aws_h1_decoder *decoder, struct a /* RFC-7230 section 4.1 Chunked Transfer Encoding */ if (AWS_UNLIKELY(input.len != 0)) { AWS_LOGF_ERROR( - AWS_LS_HTTP_STREAM, "id=%p: Incoming chunk is invalid, does not end with CRLF.", decoder->logging_id); + AWS_LS_HTTP_STREAM, + "id=%p: Incoming chunk is invalid, does not end with CRLF %zu: " PRInSTR, + decoder->logging_id, + input.len, + AWS_BYTE_CURSOR_PRI(input)); return aws_raise_error(AWS_ERROR_HTTP_PROTOCOL_ERROR); } From c48631625518ec9f097272ed1d6e9c64bd166902 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 21 Feb 2025 15:11:01 -0800 Subject: [PATCH 11/40] more prints --- source/h1_connection.c | 8 ++++++++ source/h1_decoder.c | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/h1_connection.c b/source/h1_connection.c index 747b247ef..7576eb0d7 100644 --- a/source/h1_connection.c +++ b/source/h1_connection.c @@ -2022,6 +2022,14 @@ static int s_try_process_next_stream_read_message(struct aws_h1_connection *conn */ message_cursor.len = (size_t)aws_min_u64(message_cursor.len, stream_window); + AWS_LOGF_TRACE( + AWS_LS_HTTP_CONNECTION, + "id=%p: Processing %zu bytes of message for stream %p, %zu bytes remain.", + (void *)&connection->base, + message_cursor.len, + (void *)&incoming_stream->base, + queued_msg->message_data.len - queued_msg->copy_mark); + const size_t prev_cursor_len = message_cursor.len; /* Set some decoder state, based on current stream */ diff --git a/source/h1_decoder.c b/source/h1_decoder.c index ae7a65d07..c33a11aa9 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -209,8 +209,14 @@ static int s_mark_done(struct aws_h1_decoder *decoder) { /* Reset state, in preparation for processing a new message */ static void s_reset_state(struct aws_h1_decoder *decoder) { if (decoder->is_decoding_requests) { + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, "id=%p: Resetting decoder for new request, is_decoding_requests.", decoder->logging_id); s_set_line_state(decoder, s_linestate_request); } else { + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: Resetting decoder for new request, not is_decoding_requests", + decoder->logging_id); s_set_line_state(decoder, s_linestate_response); } @@ -270,7 +276,6 @@ static int s_linestate_chunk_terminator(struct aws_h1_decoder *decoder, struct a AWS_BYTE_CURSOR_PRI(input)); return aws_raise_error(AWS_ERROR_HTTP_PROTOCOL_ERROR); } - s_set_line_state(decoder, s_linestate_chunk_size); return AWS_OP_SUCCESS; @@ -296,6 +301,11 @@ static int s_state_chunk(struct aws_h1_decoder *decoder, struct aws_byte_cursor } if (AWS_LIKELY(finished)) { + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: Finished reading chunk of size %d : " PRIu64, + decoder->logging_id, + decoder->chunk_size); s_set_line_state(decoder, s_linestate_chunk_terminator); } @@ -342,6 +352,11 @@ static int s_linestate_chunk_size(struct aws_h1_decoder *decoder, struct aws_byt /* Expected empty newline and end of message. */ decoder->doing_trailers = true; + + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_line_state in s_linestate_chunk_size, set to s_linestate_header", + decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; } From d7efa17b1337a4bca5f86fcfe0d8bbac1b641f40 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 21 Feb 2025 15:17:35 -0800 Subject: [PATCH 12/40] print more --- source/h1_decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/h1_decoder.c b/source/h1_decoder.c index c33a11aa9..0ba626c30 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -303,7 +303,7 @@ static int s_state_chunk(struct aws_h1_decoder *decoder, struct aws_byte_cursor if (AWS_LIKELY(finished)) { AWS_LOGF_TRACE( AWS_LS_HTTP_STREAM, - "id=%p: Finished reading chunk of size %d : " PRIu64, + "id=%p: Finished reading chunk of size %llu, set to s_linestate_chunk_terminator", decoder->logging_id, decoder->chunk_size); s_set_line_state(decoder, s_linestate_chunk_terminator); From 233e25823ef8bc5a21d13e1f9c99c6dda18cd311 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 09:55:56 -0800 Subject: [PATCH 13/40] more prints for set_line/state --- source/h1_decoder.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/source/h1_decoder.c b/source/h1_decoder.c index 0ba626c30..94e440857 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -210,13 +210,11 @@ static int s_mark_done(struct aws_h1_decoder *decoder) { static void s_reset_state(struct aws_h1_decoder *decoder) { if (decoder->is_decoding_requests) { AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, "id=%p: Resetting decoder for new request, is_decoding_requests.", decoder->logging_id); + AWS_LS_HTTP_STREAM, "id=%p: s_set_line_state in s_reset_state, s_linestate_request.", decoder->logging_id); s_set_line_state(decoder, s_linestate_request); } else { AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: Resetting decoder for new request, not is_decoding_requests", - decoder->logging_id); + AWS_LS_HTTP_STREAM, "id=%p: s_set_line_state in s_reset_state, s_linestate_response." decoder->logging_id); s_set_line_state(decoder, s_linestate_response); } @@ -276,6 +274,10 @@ static int s_linestate_chunk_terminator(struct aws_h1_decoder *decoder, struct a AWS_BYTE_CURSOR_PRI(input)); return aws_raise_error(AWS_ERROR_HTTP_PROTOCOL_ERROR); } + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_line_state in s_linestate_chunk_terminator, s_linestate_chunk_size." decoder->logging_id); + s_set_line_state(decoder, s_linestate_chunk_size); return AWS_OP_SUCCESS; @@ -364,6 +366,8 @@ static int s_linestate_chunk_size(struct aws_h1_decoder *decoder, struct aws_byt /* Skip all chunk extensions, as they are optional. */ /* RFC-7230 section 4.1.1 Chunk Extensions */ + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, "id=%p: s_set_state in s_linestate_chunk_size, set to s_state_chunk", decoder->logging_id); s_set_state(decoder, s_state_chunk); return AWS_OP_SUCCESS; @@ -383,8 +387,16 @@ static int s_linestate_header(struct aws_h1_decoder *decoder, struct aws_byte_cu return AWS_OP_ERR; } } else if (decoder->transfer_encoding & AWS_HTTP_TRANSFER_ENCODING_CHUNKED) { + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_line_state in s_linestate_header, set to s_linestate_chunk_size", + decoder->logging_id); s_set_line_state(decoder, s_linestate_chunk_size); } else if (decoder->content_length > 0) { + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_state in s_linestate_header, set to s_state_unchunked_body", + decoder->logging_id); s_set_state(decoder, s_state_unchunked_body); } else { err = s_mark_done(decoder); @@ -564,6 +576,10 @@ static int s_linestate_header(struct aws_h1_decoder *decoder, struct aws_byte_cu return AWS_OP_ERR; } + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_line_state in s_linestate_header, set to s_linestate_header", + decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; @@ -636,6 +652,10 @@ static int s_linestate_request(struct aws_h1_decoder *decoder, struct aws_byte_c return AWS_OP_ERR; } + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_line_state in s_linestate_request, set to s_linestate_header", + decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; @@ -709,6 +729,10 @@ static int s_linestate_response(struct aws_h1_decoder *decoder, struct aws_byte_ return AWS_OP_ERR; } + AWS_LOGF_TRACE( + AWS_LS_HTTP_STREAM, + "id=%p: s_set_line_state in s_linestate_response, set to s_linestate_header", + decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; } From aac4b01242cd8d8987452480ea144c4aa4a0296f Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 09:58:02 -0800 Subject: [PATCH 14/40] prints --- source/h1_decoder.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/h1_decoder.c b/source/h1_decoder.c index 94e440857..87aac7675 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -214,7 +214,7 @@ static void s_reset_state(struct aws_h1_decoder *decoder) { s_set_line_state(decoder, s_linestate_request); } else { AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, "id=%p: s_set_line_state in s_reset_state, s_linestate_response." decoder->logging_id); + AWS_LS_HTTP_STREAM, "id=%p: s_set_line_state in s_reset_state, s_linestate_response.", decoder->logging_id); s_set_line_state(decoder, s_linestate_response); } @@ -276,7 +276,8 @@ static int s_linestate_chunk_terminator(struct aws_h1_decoder *decoder, struct a } AWS_LOGF_TRACE( AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_chunk_terminator, s_linestate_chunk_size." decoder->logging_id); + "id=%p: s_set_line_state in s_linestate_chunk_terminator, s_linestate_chunk_size.", + decoder->logging_id); s_set_line_state(decoder, s_linestate_chunk_size); From ba8a7e2f95dd226e4d28126a45091fc2b1e36e45 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 11:39:55 -0800 Subject: [PATCH 15/40] test on different macos os version --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b1a0af37..b1be42cb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,11 +204,15 @@ jobs: python .\aws-c-http\build\deps\aws-c-common\scripts\appverifier_ctest.py --build_directory .\aws-c-http\build\aws-c-http macos: - runs-on: macos-14 # latest + runs-on: ${{ matrix.runner }} strategy: fail-fast: false matrix: eventloop: ["kqueue", "dispatch_queue"] + runner: + - macos-13 # x64 + - macos-14 + - macos-15 steps: - uses: aws-actions/configure-aws-credentials@v4 with: From 2db9954a3ca283b45422b60b4c23e26273e97d03 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 15:22:06 -0800 Subject: [PATCH 16/40] revert test --- tests/test_tls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index dbc0285cc..674f43a73 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -219,7 +219,7 @@ static int s_test_tls_download_medium_file_general( /* wait for the request to complete */ s_test_wait(&test, s_stream_wait_pred); - ASSERT_INT_EQUALS(181251, test.body_size); + ASSERT_INT_EQUALS(14428801, test.body_size); aws_http_message_destroy(request); aws_http_stream_release(test.stream); @@ -238,7 +238,7 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("stspn.com/"); + aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } From 75567b3f670f45042b20a324c2ae553bce9d3a09 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 15:36:59 -0800 Subject: [PATCH 17/40] try h2 with plain --- tests/test_tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index 674f43a73..ad56513d7 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -247,7 +247,7 @@ AWS_TEST_CASE(tls_download_medium_file_h1, s_test_tls_download_medium_file_h1); static int s_tls_download_medium_file_h2(struct aws_allocator *allocator, void *ctx) { (void)ctx; /* The cloudfront domain for aws-crt-test-stuff */ - struct aws_byte_cursor url = aws_byte_cursor_from_c_str("https://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt"); + struct aws_byte_cursor url = aws_byte_cursor_from_c_str("http://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, true /*h2_required*/)); return AWS_OP_SUCCESS; } From 32e6e2183adf1f9948d211ca900493d82c644d5d Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 15:43:24 -0800 Subject: [PATCH 18/40] try non-tls test --- tests/test_tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index ad56513d7..782c6542f 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -258,7 +258,7 @@ static int s_test_tls_download_shutdown_with_window_size_0(struct aws_allocator aws_http_library_init(allocator); struct aws_byte_cursor uri_str = - aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); struct aws_uri uri; AWS_ZERO_STRUCT(uri); aws_uri_init_parse(&uri, allocator, &uri_str); From 31e5b0708b05dfb7763ba4b910822c88dd0a00a8 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 15:59:55 -0800 Subject: [PATCH 19/40] revert unit test --- tests/test_tls.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index 782c6542f..22b92e8d0 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -177,11 +177,11 @@ static int s_test_tls_download_medium_file_general( http_options.allocator = test.alloc; http_options.bootstrap = test.client_bootstrap; http_options.host_name = *aws_uri_host_name(&uri); - http_options.port = 80; + http_options.port = 443; http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; - //http_options.tls_options = &tls_connection_options; + http_options.tls_options = &tls_connection_options; http_options.user_data = &test; ASSERT_SUCCESS(aws_http_client_connect(&http_options)); @@ -238,7 +238,7 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } @@ -247,7 +247,7 @@ AWS_TEST_CASE(tls_download_medium_file_h1, s_test_tls_download_medium_file_h1); static int s_tls_download_medium_file_h2(struct aws_allocator *allocator, void *ctx) { (void)ctx; /* The cloudfront domain for aws-crt-test-stuff */ - struct aws_byte_cursor url = aws_byte_cursor_from_c_str("http://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt"); + struct aws_byte_cursor url = aws_byte_cursor_from_c_str("https://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, true /*h2_required*/)); return AWS_OP_SUCCESS; } @@ -258,7 +258,7 @@ static int s_test_tls_download_shutdown_with_window_size_0(struct aws_allocator aws_http_library_init(allocator); struct aws_byte_cursor uri_str = - aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); struct aws_uri uri; AWS_ZERO_STRUCT(uri); aws_uri_init_parse(&uri, allocator, &uri_str); From 7cdb573ab08058bff45d54140b57a75d55da3758 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 24 Feb 2025 16:11:56 -0800 Subject: [PATCH 20/40] use s3 plain test --- tests/test_tls.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index 22b92e8d0..db1588379 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -177,11 +177,11 @@ static int s_test_tls_download_medium_file_general( http_options.allocator = test.alloc; http_options.bootstrap = test.client_bootstrap; http_options.host_name = *aws_uri_host_name(&uri); - http_options.port = 443; + http_options.port = 80; http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; - http_options.tls_options = &tls_connection_options; + // http_options.tls_options = &tls_connection_options; http_options.user_data = &test; ASSERT_SUCCESS(aws_http_client_connect(&http_options)); @@ -238,7 +238,7 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } @@ -247,7 +247,8 @@ AWS_TEST_CASE(tls_download_medium_file_h1, s_test_tls_download_medium_file_h1); static int s_tls_download_medium_file_h2(struct aws_allocator *allocator, void *ctx) { (void)ctx; /* The cloudfront domain for aws-crt-test-stuff */ - struct aws_byte_cursor url = aws_byte_cursor_from_c_str("https://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt"); + struct aws_byte_cursor url = + aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, true /*h2_required*/)); return AWS_OP_SUCCESS; } @@ -258,7 +259,7 @@ static int s_test_tls_download_shutdown_with_window_size_0(struct aws_allocator aws_http_library_init(allocator); struct aws_byte_cursor uri_str = - aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); struct aws_uri uri; AWS_ZERO_STRUCT(uri); aws_uri_init_parse(&uri, allocator, &uri_str); From 7689c3b6112acf31e382529191c710e758fb64d1 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 25 Feb 2025 09:36:50 -0800 Subject: [PATCH 21/40] revert unit test --- tests/test_tls.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index db1588379..8d90c1f0f 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -177,11 +177,11 @@ static int s_test_tls_download_medium_file_general( http_options.allocator = test.alloc; http_options.bootstrap = test.client_bootstrap; http_options.host_name = *aws_uri_host_name(&uri); - http_options.port = 80; + http_options.port = 443; http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; - // http_options.tls_options = &tls_connection_options; + http_options.tls_options = &tls_connection_options; http_options.user_data = &test; ASSERT_SUCCESS(aws_http_client_connect(&http_options)); @@ -247,8 +247,7 @@ AWS_TEST_CASE(tls_download_medium_file_h1, s_test_tls_download_medium_file_h1); static int s_tls_download_medium_file_h2(struct aws_allocator *allocator, void *ctx) { (void)ctx; /* The cloudfront domain for aws-crt-test-stuff */ - struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + struct aws_byte_cursor url = aws_byte_cursor_from_c_str("https://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, true /*h2_required*/)); return AWS_OP_SUCCESS; } @@ -259,7 +258,7 @@ static int s_test_tls_download_shutdown_with_window_size_0(struct aws_allocator aws_http_library_init(allocator); struct aws_byte_cursor uri_str = - aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); struct aws_uri uri; AWS_ZERO_STRUCT(uri); aws_uri_init_parse(&uri, allocator, &uri_str); From 891f500ca73d940b1d2b38d9fa4a83728cf3f1a4 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 25 Feb 2025 13:01:23 -0800 Subject: [PATCH 22/40] test against static stspn --- tests/test_tls.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index 8d90c1f0f..a41487cbb 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -177,11 +177,11 @@ static int s_test_tls_download_medium_file_general( http_options.allocator = test.alloc; http_options.bootstrap = test.client_bootstrap; http_options.host_name = *aws_uri_host_name(&uri); - http_options.port = 443; + http_options.port = 80; http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; - http_options.tls_options = &tls_connection_options; + // http_options.tls_options = &tls_connection_options; http_options.user_data = &test; ASSERT_SUCCESS(aws_http_client_connect(&http_options)); @@ -219,7 +219,7 @@ static int s_test_tls_download_medium_file_general( /* wait for the request to complete */ s_test_wait(&test, s_stream_wait_pred); - ASSERT_INT_EQUALS(14428801, test.body_size); + ASSERT_INT_EQUALS(181476, test.body_size); aws_http_message_destroy(request); aws_http_stream_release(test.stream); @@ -238,7 +238,7 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); + aws_byte_cursor_from_c_str("http://aws-c-s3-test-bucket-public.s3.us-west-2.amazonaws.com/stspn.html"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } From a26c5271c9294fe705b6c5d3b5af6dfcf7697a60 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 25 Feb 2025 14:02:31 -0800 Subject: [PATCH 23/40] test with a 200m file --- tests/test_tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index a41487cbb..b1004f1c0 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -238,7 +238,7 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("http://aws-c-s3-test-bucket-public.s3.us-west-2.amazonaws.com/stspn.html"); + aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.us-east-1.amazonaws.com/s3log.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } From 71d071dc451d8cc2463782fa6d841295e4d72058 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 25 Feb 2025 14:14:05 -0800 Subject: [PATCH 24/40] 200m is too large, try 134m --- tests/test_tls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index b1004f1c0..ec202ca4b 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -237,8 +237,8 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; - struct aws_byte_cursor url = - aws_byte_cursor_from_c_str("http://aws-crt-test-stuff.s3.us-east-1.amazonaws.com/s3log.txt"); + struct aws_byte_cursor url = aws_byte_cursor_from_c_str( + "http://aws-crt-test-stuff-us-west-2.s3.us-west-2.amazonaws.com/put_object_test_128MB.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } From 0e4fac899b92afa8befdbfb974a41d1bae7a55e4 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 25 Feb 2025 22:23:43 -0800 Subject: [PATCH 25/40] revert the test again --- tests/test_tls.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index ec202ca4b..b71b0f653 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -177,7 +177,7 @@ static int s_test_tls_download_medium_file_general( http_options.allocator = test.alloc; http_options.bootstrap = test.client_bootstrap; http_options.host_name = *aws_uri_host_name(&uri); - http_options.port = 80; + http_options.port = 443; http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; @@ -219,7 +219,7 @@ static int s_test_tls_download_medium_file_general( /* wait for the request to complete */ s_test_wait(&test, s_stream_wait_pred); - ASSERT_INT_EQUALS(181476, test.body_size); + ASSERT_INT_EQUALS(14428801, test.body_size); aws_http_message_destroy(request); aws_http_stream_release(test.stream); @@ -237,8 +237,8 @@ static int s_test_tls_download_medium_file_general( static int s_test_tls_download_medium_file_h1(struct aws_allocator *allocator, void *ctx) { (void)ctx; - struct aws_byte_cursor url = aws_byte_cursor_from_c_str( - "http://aws-crt-test-stuff-us-west-2.s3.us-west-2.amazonaws.com/put_object_test_128MB.txt"); + struct aws_byte_cursor url = + aws_byte_cursor_from_c_str("https://aws-crt-test-stuff.s3.amazonaws.com/http_test_doc.txt"); ASSERT_SUCCESS(s_test_tls_download_medium_file_general(allocator, url, false /*h2_required*/)); return AWS_OP_SUCCESS; } From a2077edf0118a663a0aab87725e709720979a94f Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 26 Feb 2025 10:42:57 -0800 Subject: [PATCH 26/40] forgot to revert the tls option --- tests/test_tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index b71b0f653..22b92e8d0 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -181,7 +181,7 @@ static int s_test_tls_download_medium_file_general( http_options.on_setup = s_on_connection_setup; http_options.on_shutdown = s_on_connection_shutdown; http_options.socket_options = &socket_options; - // http_options.tls_options = &tls_connection_options; + http_options.tls_options = &tls_connection_options; http_options.user_data = &test; ASSERT_SUCCESS(aws_http_client_connect(&http_options)); From 4341fed90c14b42c4f63e51265a56b8f176073ed Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 26 Feb 2025 11:50:03 -0800 Subject: [PATCH 27/40] cleanup testing prints --- source/h1_connection.c | 14 +------------ source/h1_decoder.c | 45 ------------------------------------------ 2 files changed, 1 insertion(+), 58 deletions(-) diff --git a/source/h1_connection.c b/source/h1_connection.c index 7576eb0d7..b3addef50 100644 --- a/source/h1_connection.c +++ b/source/h1_connection.c @@ -1386,11 +1386,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished, } AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: Incoming body: %zu bytes received: " PRInSTR, - (void *)&incoming_stream->base, - data->len, - AWS_BYTE_CURSOR_PRI(*data)); + AWS_LS_HTTP_STREAM, "id=%p: Incoming body: %zu bytes received.", (void *)&incoming_stream->base, data->len); if (connection->base.stream_manual_window_management) { /* Let stream window shrink by amount of body data received */ @@ -2022,14 +2018,6 @@ static int s_try_process_next_stream_read_message(struct aws_h1_connection *conn */ message_cursor.len = (size_t)aws_min_u64(message_cursor.len, stream_window); - AWS_LOGF_TRACE( - AWS_LS_HTTP_CONNECTION, - "id=%p: Processing %zu bytes of message for stream %p, %zu bytes remain.", - (void *)&connection->base, - message_cursor.len, - (void *)&incoming_stream->base, - queued_msg->message_data.len - queued_msg->copy_mark); - const size_t prev_cursor_len = message_cursor.len; /* Set some decoder state, based on current stream */ diff --git a/source/h1_decoder.c b/source/h1_decoder.c index 87aac7675..63c059fd6 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -209,12 +209,8 @@ static int s_mark_done(struct aws_h1_decoder *decoder) { /* Reset state, in preparation for processing a new message */ static void s_reset_state(struct aws_h1_decoder *decoder) { if (decoder->is_decoding_requests) { - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, "id=%p: s_set_line_state in s_reset_state, s_linestate_request.", decoder->logging_id); s_set_line_state(decoder, s_linestate_request); } else { - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, "id=%p: s_set_line_state in s_reset_state, s_linestate_response.", decoder->logging_id); s_set_line_state(decoder, s_linestate_response); } @@ -266,18 +262,8 @@ static int s_linestate_chunk_terminator(struct aws_h1_decoder *decoder, struct a /* Expecting CRLF at end of each chunk */ /* RFC-7230 section 4.1 Chunked Transfer Encoding */ if (AWS_UNLIKELY(input.len != 0)) { - AWS_LOGF_ERROR( - AWS_LS_HTTP_STREAM, - "id=%p: Incoming chunk is invalid, does not end with CRLF %zu: " PRInSTR, - decoder->logging_id, - input.len, - AWS_BYTE_CURSOR_PRI(input)); return aws_raise_error(AWS_ERROR_HTTP_PROTOCOL_ERROR); } - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_chunk_terminator, s_linestate_chunk_size.", - decoder->logging_id); s_set_line_state(decoder, s_linestate_chunk_size); @@ -304,11 +290,6 @@ static int s_state_chunk(struct aws_h1_decoder *decoder, struct aws_byte_cursor } if (AWS_LIKELY(finished)) { - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: Finished reading chunk of size %llu, set to s_linestate_chunk_terminator", - decoder->logging_id, - decoder->chunk_size); s_set_line_state(decoder, s_linestate_chunk_terminator); } @@ -356,10 +337,6 @@ static int s_linestate_chunk_size(struct aws_h1_decoder *decoder, struct aws_byt /* Expected empty newline and end of message. */ decoder->doing_trailers = true; - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_chunk_size, set to s_linestate_header", - decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; } @@ -367,8 +344,6 @@ static int s_linestate_chunk_size(struct aws_h1_decoder *decoder, struct aws_byt /* Skip all chunk extensions, as they are optional. */ /* RFC-7230 section 4.1.1 Chunk Extensions */ - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, "id=%p: s_set_state in s_linestate_chunk_size, set to s_state_chunk", decoder->logging_id); s_set_state(decoder, s_state_chunk); return AWS_OP_SUCCESS; @@ -388,16 +363,8 @@ static int s_linestate_header(struct aws_h1_decoder *decoder, struct aws_byte_cu return AWS_OP_ERR; } } else if (decoder->transfer_encoding & AWS_HTTP_TRANSFER_ENCODING_CHUNKED) { - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_header, set to s_linestate_chunk_size", - decoder->logging_id); s_set_line_state(decoder, s_linestate_chunk_size); } else if (decoder->content_length > 0) { - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_state in s_linestate_header, set to s_state_unchunked_body", - decoder->logging_id); s_set_state(decoder, s_state_unchunked_body); } else { err = s_mark_done(decoder); @@ -577,10 +544,6 @@ static int s_linestate_header(struct aws_h1_decoder *decoder, struct aws_byte_cu return AWS_OP_ERR; } - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_header, set to s_linestate_header", - decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; @@ -653,10 +616,6 @@ static int s_linestate_request(struct aws_h1_decoder *decoder, struct aws_byte_c return AWS_OP_ERR; } - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_request, set to s_linestate_header", - decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; @@ -730,10 +689,6 @@ static int s_linestate_response(struct aws_h1_decoder *decoder, struct aws_byte_ return AWS_OP_ERR; } - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: s_set_line_state in s_linestate_response, set to s_linestate_header", - decoder->logging_id); s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; } From 42bf9bd30a31d00a38a6c9a455590426a16a78cf Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 26 Feb 2025 11:57:33 -0800 Subject: [PATCH 28/40] update ci runner --- .github/workflows/ci.yml | 10 +++------- source/h1_decoder.c | 11 ++--------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1be42cb0..0c6e9402d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,15 +204,11 @@ jobs: python .\aws-c-http\build\deps\aws-c-common\scripts\appverifier_ctest.py --build_directory .\aws-c-http\build\aws-c-http macos: - runs-on: ${{ matrix.runner }} + runs-on: macos-14 strategy: fail-fast: false matrix: eventloop: ["kqueue", "dispatch_queue"] - runner: - - macos-13 # x64 - - macos-14 - - macos-15 steps: - uses: aws-actions/configure-aws-credentials@v4 with: @@ -225,7 +221,7 @@ jobs: ./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} macos-x64: - runs-on: macos-14-large # latest + runs-on: macos-14-large steps: - uses: aws-actions/configure-aws-credentials@v4 with: @@ -252,7 +248,7 @@ jobs: python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --config Debug localhost-test-macos: - runs-on: macos-14 # latest + runs-on: macos-14 strategy: fail-fast: false matrix: diff --git a/source/h1_decoder.c b/source/h1_decoder.c index 63c059fd6..2468c449b 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -98,15 +98,6 @@ static int s_state_getline(struct aws_h1_decoder *decoder, struct aws_byte_curso size_t line_length = 0; bool found_crlf = s_scan_for_crlf(decoder, *input, &line_length); - AWS_LOGF_TRACE( - AWS_LS_HTTP_STREAM, - "id=%p: Found CRLF: %d, has_prev_data: %d, line_length: %zu, data is " PRInSTR, - decoder->logging_id, - found_crlf, - has_prev_data, - line_length, - AWS_BYTE_CURSOR_PRI(*input)); - /* Found end of line! Run the line processor on it */ struct aws_byte_cursor line = aws_byte_cursor_advance(input, line_length); @@ -262,6 +253,8 @@ static int s_linestate_chunk_terminator(struct aws_h1_decoder *decoder, struct a /* Expecting CRLF at end of each chunk */ /* RFC-7230 section 4.1 Chunked Transfer Encoding */ if (AWS_UNLIKELY(input.len != 0)) { + AWS_LOGF_ERROR( + AWS_LS_HTTP_STREAM, "id=%p: Incoming chunk is invalid, does not end with CRLF.", decoder->logging_id); return aws_raise_error(AWS_ERROR_HTTP_PROTOCOL_ERROR); } From 62cd70361deee93ac1395e23cd9752094a46b783 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 28 Feb 2025 15:17:21 -0800 Subject: [PATCH 29/40] kick ci From 5a7f7c5e3f4dc706c5dcb15cd3dc908c7f04c358 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Wed, 5 Mar 2025 15:12:58 -0800 Subject: [PATCH 30/40] remove aws_server_bootstrap_new_socket_listener_async --- source/connection.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/source/connection.c b/source/connection.c index 25d2b998a..879bbbc3b 100644 --- a/source/connection.c +++ b/source/connection.c @@ -729,35 +729,21 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options }; int listen_error = AWS_OP_SUCCESS; -#if (defined(AWS_ENABLE_DISPATCH_QUEUE) && !defined(AWS_ENABLE_KQUEUE)) || defined(AWS_USE_APPLE_NETWORK_FRAMEWORK) -# define AWS_NETWORK_FRAMEWORK_ENABLED 1 -#else -# define AWS_NETWORK_FRAMEWORK_ENABLED 0 -#endif - if (bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK || - (AWS_NETWORK_FRAMEWORK_ENABLED && - bootstrap_options.socket_options->impl_type == AWS_SOCKET_IMPL_PLATFORM_DEFAULT)) { - /* - * WARNING!!!! - * For Apple Network Framework, socket listen is an async function, we would need block here waiting for - * setup complete. - */ - server->socket = aws_server_bootstrap_new_socket_listener_async(&bootstrap_options); - aws_mutex_lock(&server_user_data->mutex); - aws_condition_variable_wait_pred( - &server_user_data->condition_variable, - &server_user_data->mutex, - s_listener_connected_predicate, - server_user_data); - aws_mutex_unlock(&server_user_data->mutex); - listen_error = server_user_data->setup_error_code; - } else { - server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); - if (!server->socket) { - listen_error = aws_last_error(); - } - } + /* + * WARNING!!!! + * aws_server_bootstrap_new_socket_listener has async callback, we would block here waiting for + * setup complete. + */ + server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); + aws_mutex_lock(&server_user_data->mutex); + aws_condition_variable_wait_pred( + &server_user_data->condition_variable, + &server_user_data->mutex, + s_listener_connected_predicate, + server_user_data); + aws_mutex_unlock(&server_user_data->mutex); + listen_error = server_user_data->setup_error_code; s_server_unlock_synced_data(server); From 629c8389c6cf06525675c51a88601d9c1b9154da Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Thu, 6 Mar 2025 11:05:03 -0800 Subject: [PATCH 31/40] handle listener setup error --- source/connection.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/source/connection.c b/source/connection.c index 879bbbc3b..87037dcbe 100644 --- a/source/connection.c +++ b/source/connection.c @@ -736,15 +736,20 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options * setup complete. */ server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); - aws_mutex_lock(&server_user_data->mutex); - aws_condition_variable_wait_pred( - &server_user_data->condition_variable, - &server_user_data->mutex, - s_listener_connected_predicate, - server_user_data); - aws_mutex_unlock(&server_user_data->mutex); - listen_error = server_user_data->setup_error_code; - + // if server setup properly, waiting for setup callback + if (server->socket) { + aws_mutex_lock(&server_user_data->mutex); + aws_condition_variable_wait_pred( + &server_user_data->condition_variable, + &server_user_data->mutex, + s_listener_connected_predicate, + server_user_data); + aws_mutex_unlock(&server_user_data->mutex); + listen_error = server_user_data->setup_error_code; + } + else{ + listen_error = aws_last_error(); + } s_server_unlock_synced_data(server); if (listen_error) { From 8fe08ac758b874e2ce364e2ba5de7e58c3f25407 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Thu, 6 Mar 2025 11:05:23 -0800 Subject: [PATCH 32/40] clang-format --- source/connection.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/connection.c b/source/connection.c index 87037dcbe..d41c24f57 100644 --- a/source/connection.c +++ b/source/connection.c @@ -746,8 +746,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options server_user_data); aws_mutex_unlock(&server_user_data->mutex); listen_error = server_user_data->setup_error_code; - } - else{ + } else { listen_error = aws_last_error(); } s_server_unlock_synced_data(server); From 85bd1c69db71c8237ba356212f628fd231d3f186 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 10:05:01 -0700 Subject: [PATCH 33/40] update to use future --- source/connection.c | 53 ++++++++++++++++++--------------------------- source/h1_decoder.c | 1 - 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/source/connection.c b/source/connection.c index d41c24f57..ec0cd210b 100644 --- a/source/connection.c +++ b/source/connection.c @@ -11,12 +11,12 @@ #include -#include #include #include #include #include #include +#include #include #include #include @@ -435,10 +435,7 @@ void aws_http_connection_release(struct aws_http_connection *connection) { struct aws_server_user_data { struct aws_allocator *alloc; struct aws_http_server *server; - struct aws_mutex mutex; - struct aws_condition_variable condition_variable; - int setup_error_code; - bool setup_complete; + struct aws_future_void *setup_future; }; /* At this point, the server bootstrapper has accepted an incoming connection from a client and set up a channel. @@ -590,6 +587,12 @@ static void s_http_server_clean_up(struct aws_http_server *server) { aws_mem_release(server->alloc, server); } +static void s_http_server_user_data_clean_up(struct aws_server_user_data *server_user_data) { + s_http_server_clean_up(server_user_data->server); + aws_future_void_release(server_user_data->setup_future); + aws_mem_release(server_user_data->alloc, server_user_data); +} + /* At this point, the channel for a server connection has completed shutdown, but hasn't been destroyed yet. */ static void s_server_bootstrap_on_accept_channel_shutdown( struct aws_server_bootstrap *bootstrap, @@ -630,15 +633,7 @@ static void s_server_bootstrap_on_server_listener_destroy(struct aws_server_boot (void)bootstrap; AWS_ASSERT(user_data); struct aws_server_user_data *server_user_data = user_data; - struct aws_http_server *server = server_user_data->server; - s_http_server_clean_up(server); - aws_mem_release(server_user_data->alloc, server_user_data); -} - -static bool s_listener_connected_predicate(void *user_data) { - struct aws_server_user_data *setup_test_args = (struct aws_server_user_data *)user_data; - bool finished = setup_test_args->setup_complete; - return finished; + s_http_server_user_data_clean_up(server_user_data); } /* the server listener has finished setup. We released the socket if error_code is not 0. */ @@ -648,11 +643,11 @@ static void s_server_bootstrap_on_server_listener_setup( void *user_data) { (void)bootstrap; struct aws_server_user_data *server_user_data = user_data; - aws_mutex_lock(&server_user_data->mutex); - server_user_data->setup_error_code = error_code; - server_user_data->setup_complete = true; - aws_condition_variable_notify_one(&server_user_data->condition_variable); - aws_mutex_unlock(&server_user_data->mutex); + if (error_code) { + aws_future_void_set_error(server_user_data->setup_future, error_code); + } else { + aws_future_void_set_result(server_user_data->setup_future); + } } struct aws_http_server *aws_http_server_new(const struct aws_http_server_options *options) { @@ -710,9 +705,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options aws_mem_calloc(options->allocator, 1, sizeof(struct aws_server_user_data)); server_user_data->server = server; server_user_data->alloc = options->allocator; - aws_mutex_init(&server_user_data->mutex); - aws_condition_variable_init(&server_user_data->condition_variable); - server_user_data->setup_complete = false; + server_user_data->setup_future = aws_future_void_new(options->allocator); struct aws_server_socket_channel_bootstrap_options bootstrap_options = { .enable_read_back_pressure = options->manual_window_management, @@ -731,21 +724,15 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options int listen_error = AWS_OP_SUCCESS; /* - * WARNING!!!! + * WARNING & TODO!!!! * aws_server_bootstrap_new_socket_listener has async callback, we would block here waiting for - * setup complete. + * setup complete. aws-c-http library need to be updated with a proper async API. */ server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); // if server setup properly, waiting for setup callback if (server->socket) { - aws_mutex_lock(&server_user_data->mutex); - aws_condition_variable_wait_pred( - &server_user_data->condition_variable, - &server_user_data->mutex, - s_listener_connected_predicate, - server_user_data); - aws_mutex_unlock(&server_user_data->mutex); - listen_error = server_user_data->setup_error_code; + aws_future_void_wait(server_user_data->setup_future, UINT64_MAX /*timeout*/); + listen_error = aws_future_void_get_error(server_user_data->setup_future); } else { listen_error = aws_last_error(); } @@ -771,6 +758,8 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options return server; socket_error: + aws_future_void_release(server_user_data->setup_future); + aws_mem_release(server_user_data->alloc, server_user_data); aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); hash_table_error: aws_mutex_clean_up(&server->synced_data.lock); diff --git a/source/h1_decoder.c b/source/h1_decoder.c index 2468c449b..c615d09a6 100644 --- a/source/h1_decoder.c +++ b/source/h1_decoder.c @@ -329,7 +329,6 @@ static int s_linestate_chunk_size(struct aws_h1_decoder *decoder, struct aws_byt /* Expected empty newline and end of message. */ decoder->doing_trailers = true; - s_set_line_state(decoder, s_linestate_header); return AWS_OP_SUCCESS; } From acf0f5c036d13370a47be22ed46db4aee3e0b7d1 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 11:04:05 -0700 Subject: [PATCH 34/40] kick ci for codebuild From 2c2c491503bd30134ea59195c0484b878affc899 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 13:48:38 -0700 Subject: [PATCH 35/40] code review update --- source/connection.c | 79 ++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/source/connection.c b/source/connection.c index ec0cd210b..b66fb6ef5 100644 --- a/source/connection.c +++ b/source/connection.c @@ -59,6 +59,7 @@ struct aws_http_server { aws_http_server_on_incoming_connection_fn *on_incoming_connection; aws_http_server_on_destroy_fn *on_destroy_complete; struct aws_socket *socket; + struct aws_future_void *setup_future; /* Any thread may touch this data, but the lock must be held */ struct { @@ -432,12 +433,6 @@ void aws_http_connection_release(struct aws_http_connection *connection) { } } -struct aws_server_user_data { - struct aws_allocator *alloc; - struct aws_http_server *server; - struct aws_future_void *setup_future; -}; - /* At this point, the server bootstrapper has accepted an incoming connection from a client and set up a channel. * Now we need to create an aws_http_connection and insert it into the channel as a channel-handler. * Note: Be careful not to access server->socket until lock is acquired to avoid race conditions */ @@ -449,8 +444,7 @@ static void s_server_bootstrap_on_accept_channel_setup( (void)bootstrap; AWS_ASSERT(user_data); - struct aws_server_user_data *server_user_data = user_data; - struct aws_http_server *server = server_user_data->server; + struct aws_http_server *server = user_data; bool user_cb_invoked = false; struct aws_http_connection *connection = NULL; if (error_code) { @@ -571,26 +565,32 @@ static void s_server_bootstrap_on_accept_channel_setup( } /* clean the server memory up */ -static void s_http_server_clean_up(struct aws_http_server *server) { +static void s_http_server_clean_up(struct aws_http_server *server, bool cleanup_mutex) { if (!server) { return; } - aws_server_bootstrap_release(server->bootstrap); + if (server->bootstrap) { + aws_server_bootstrap_release(server->bootstrap); + } /* invoke the user callback */ if (server->on_destroy_complete) { server->on_destroy_complete(server->user_data); } - aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); - aws_mutex_clean_up(&server->synced_data.lock); - aws_mem_release(server->alloc, server); -} -static void s_http_server_user_data_clean_up(struct aws_server_user_data *server_user_data) { - s_http_server_clean_up(server_user_data->server); - aws_future_void_release(server_user_data->setup_future); - aws_mem_release(server_user_data->alloc, server_user_data); + if (aws_hash_table_is_valid(&server->synced_data.channel_to_connection_map)) { + aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); + } + + if (cleanup_mutex) { + aws_mutex_clean_up(&server->synced_data.lock); + } + + if (server->setup_future) { + aws_future_void_release(server->setup_future); + } + aws_mem_release(server->alloc, server); } /* At this point, the channel for a server connection has completed shutdown, but hasn't been destroyed yet. */ @@ -602,8 +602,7 @@ static void s_server_bootstrap_on_accept_channel_shutdown( (void)bootstrap; AWS_ASSERT(user_data); - struct aws_server_user_data *server_user_data = user_data; - struct aws_http_server *server = server_user_data->server; + struct aws_http_server *server = user_data; /* Figure out which connection this was, and remove that entry from the map. * It won't be in the map if something went wrong while setting up the connection. */ @@ -632,8 +631,8 @@ static void s_server_bootstrap_on_accept_channel_shutdown( static void s_server_bootstrap_on_server_listener_destroy(struct aws_server_bootstrap *bootstrap, void *user_data) { (void)bootstrap; AWS_ASSERT(user_data); - struct aws_server_user_data *server_user_data = user_data; - s_http_server_user_data_clean_up(server_user_data); + struct aws_http_server *server_user_data = user_data; + s_http_server_clean_up(server_user_data, true /*cleanup_mutex*/); } /* the server listener has finished setup. We released the socket if error_code is not 0. */ @@ -642,11 +641,11 @@ static void s_server_bootstrap_on_server_listener_setup( int error_code, void *user_data) { (void)bootstrap; - struct aws_server_user_data *server_user_data = user_data; + struct aws_http_server *server = user_data; if (error_code) { - aws_future_void_set_error(server_user_data->setup_future, error_code); + aws_future_void_set_error(server->setup_future, error_code); } else { - aws_future_void_set_result(server_user_data->setup_future); + aws_future_void_set_result(server->setup_future); } } @@ -654,6 +653,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options aws_http_fatal_assert_library_initialized(); struct aws_http_server *server = NULL; + bool cleanup_mutex = false; if (!options || options->self_size == 0 || !options->allocator || !options->bootstrap || !options->socket_options || !options->on_incoming_connection || !options->endpoint) { @@ -683,8 +683,9 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options if (err) { AWS_LOGF_ERROR( AWS_LS_HTTP_SERVER, "static: Failed to initialize mutex, error %d (%s).", err, aws_error_name(err)); - goto mutex_error; + goto server_error; } + cleanup_mutex = true; err = aws_hash_table_init( &server->synced_data.channel_to_connection_map, server->alloc, 16, aws_hash_ptr, aws_ptr_eq, NULL, NULL); if (err) { @@ -693,7 +694,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options "static: Cannot create server, error %d (%s).", aws_last_error(), aws_error_name(aws_last_error())); - goto hash_table_error; + goto server_error; } /* Protect against callbacks firing before server->socket is set */ s_server_lock_synced_data(server); @@ -701,11 +702,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options server->is_using_tls = true; } - struct aws_server_user_data *server_user_data = - aws_mem_calloc(options->allocator, 1, sizeof(struct aws_server_user_data)); - server_user_data->server = server; - server_user_data->alloc = options->allocator; - server_user_data->setup_future = aws_future_void_new(options->allocator); + server->setup_future = aws_future_void_new(options->allocator); struct aws_server_socket_channel_bootstrap_options bootstrap_options = { .enable_read_back_pressure = options->manual_window_management, @@ -718,7 +715,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options .setup_callback = s_server_bootstrap_on_server_listener_setup, .host_name = options->endpoint->address, .port = options->endpoint->port, - .user_data = server_user_data, + .user_data = server, }; int listen_error = AWS_OP_SUCCESS; @@ -731,8 +728,8 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); // if server setup properly, waiting for setup callback if (server->socket) { - aws_future_void_wait(server_user_data->setup_future, UINT64_MAX /*timeout*/); - listen_error = aws_future_void_get_error(server_user_data->setup_future); + aws_future_void_wait(server->setup_future, UINT64_MAX /*timeout*/); + listen_error = aws_future_void_get_error(server->setup_future); } else { listen_error = aws_last_error(); } @@ -745,7 +742,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options listen_error, aws_error_name(listen_error)); - goto socket_error; + goto server_error; } AWS_LOGF_INFO( @@ -757,14 +754,8 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options return server; -socket_error: - aws_future_void_release(server_user_data->setup_future); - aws_mem_release(server_user_data->alloc, server_user_data); - aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); -hash_table_error: - aws_mutex_clean_up(&server->synced_data.lock); -mutex_error: - aws_mem_release(server->alloc, server); +server_error: + s_http_server_clean_up(server, cleanup_mutex); return NULL; } From d047ebe43e336fca7d40be3673478c101f2155c7 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 13:56:12 -0700 Subject: [PATCH 36/40] clean up server socket --- source/connection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/connection.c b/source/connection.c index b66fb6ef5..88d87e1fe 100644 --- a/source/connection.c +++ b/source/connection.c @@ -631,8 +631,8 @@ static void s_server_bootstrap_on_accept_channel_shutdown( static void s_server_bootstrap_on_server_listener_destroy(struct aws_server_bootstrap *bootstrap, void *user_data) { (void)bootstrap; AWS_ASSERT(user_data); - struct aws_http_server *server_user_data = user_data; - s_http_server_clean_up(server_user_data, true /*cleanup_mutex*/); + struct aws_http_server *server = user_data; + s_http_server_clean_up(server, true /*cleanup_mutex*/); } /* the server listener has finished setup. We released the socket if error_code is not 0. */ From 957e9f58c259e714989279ab3b0e096e0ad40852 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 15:47:17 -0700 Subject: [PATCH 37/40] remove unnecessary validation --- source/connection.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/source/connection.c b/source/connection.c index 88d87e1fe..01959da96 100644 --- a/source/connection.c +++ b/source/connection.c @@ -570,26 +570,16 @@ static void s_http_server_clean_up(struct aws_http_server *server, bool cleanup_ return; } - if (server->bootstrap) { - aws_server_bootstrap_release(server->bootstrap); - } + aws_server_bootstrap_release(server->bootstrap); /* invoke the user callback */ if (server->on_destroy_complete) { server->on_destroy_complete(server->user_data); } - if (aws_hash_table_is_valid(&server->synced_data.channel_to_connection_map)) { - aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); - } - - if (cleanup_mutex) { - aws_mutex_clean_up(&server->synced_data.lock); - } - - if (server->setup_future) { - aws_future_void_release(server->setup_future); - } + aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); + aws_mutex_clean_up(&server->synced_data.lock); + aws_future_void_release(server->setup_future); aws_mem_release(server->alloc, server); } From 1594c972d826529be9a425475f3f0d05197b3564 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 15:50:44 -0700 Subject: [PATCH 38/40] remove mutex flag --- source/connection.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/connection.c b/source/connection.c index 01959da96..634968a73 100644 --- a/source/connection.c +++ b/source/connection.c @@ -565,7 +565,7 @@ static void s_server_bootstrap_on_accept_channel_setup( } /* clean the server memory up */ -static void s_http_server_clean_up(struct aws_http_server *server, bool cleanup_mutex) { +static void s_http_server_clean_up(struct aws_http_server *server) { if (!server) { return; } @@ -622,7 +622,7 @@ static void s_server_bootstrap_on_server_listener_destroy(struct aws_server_boot (void)bootstrap; AWS_ASSERT(user_data); struct aws_http_server *server = user_data; - s_http_server_clean_up(server, true /*cleanup_mutex*/); + s_http_server_clean_up(server); } /* the server listener has finished setup. We released the socket if error_code is not 0. */ @@ -643,7 +643,6 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options aws_http_fatal_assert_library_initialized(); struct aws_http_server *server = NULL; - bool cleanup_mutex = false; if (!options || options->self_size == 0 || !options->allocator || !options->bootstrap || !options->socket_options || !options->on_incoming_connection || !options->endpoint) { @@ -675,7 +674,6 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options AWS_LS_HTTP_SERVER, "static: Failed to initialize mutex, error %d (%s).", err, aws_error_name(err)); goto server_error; } - cleanup_mutex = true; err = aws_hash_table_init( &server->synced_data.channel_to_connection_map, server->alloc, 16, aws_hash_ptr, aws_ptr_eq, NULL, NULL); if (err) { @@ -745,7 +743,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options return server; server_error: - s_http_server_clean_up(server, cleanup_mutex); + s_http_server_clean_up(server); return NULL; } From 4e5908115f84c81084171ffc365d0670a58ceb60 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 17 Mar 2025 16:13:53 -0700 Subject: [PATCH 39/40] remove space --- source/connection.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/connection.c b/source/connection.c index 634968a73..83d0061a8 100644 --- a/source/connection.c +++ b/source/connection.c @@ -576,7 +576,6 @@ static void s_http_server_clean_up(struct aws_http_server *server) { if (server->on_destroy_complete) { server->on_destroy_complete(server->user_data); } - aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map); aws_mutex_clean_up(&server->synced_data.lock); aws_future_void_release(server->setup_future); From bee341b250997f94af70aa18989a9ab209cb7333 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 18 Mar 2025 09:03:13 -0700 Subject: [PATCH 40/40] Update source/connection.c raise error on listen_error Co-authored-by: Michael Graeb --- source/connection.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/connection.c b/source/connection.c index 83d0061a8..3d1a082ed 100644 --- a/source/connection.c +++ b/source/connection.c @@ -729,6 +729,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options listen_error, aws_error_name(listen_error)); + aws_raise_error(listen_error); goto server_error; }