@@ -1100,15 +1100,21 @@ static void s_write_outgoing_stream(struct aws_h1_connection *connection, bool f
11001100 AWS_LOGF_TRACE (AWS_LS_HTTP_CONNECTION , "id=%p: Outgoing stream task has begun." , (void * )& connection -> base );
11011101 }
11021102
1103- struct aws_io_message * msg = aws_channel_slot_acquire_max_message_for_write (connection -> base .channel_slot );
1104- if (!msg ) {
1105- AWS_LOGF_ERROR (
1106- AWS_LS_HTTP_CONNECTION ,
1107- "id=%p: Failed to acquire message from pool, error %d (%s). Closing connection." ,
1108- (void * )& connection -> base ,
1109- aws_last_error (),
1110- aws_error_name (aws_last_error ()));
1111- goto error ;
1103+ struct aws_io_message * msg = NULL ;
1104+ if (connection -> thread_data .pending_async_message ) {
1105+ msg = connection -> thread_data .pending_async_message ;
1106+ connection -> thread_data .pending_async_message = NULL ;
1107+ } else {
1108+ msg = aws_channel_slot_acquire_max_message_for_write (connection -> base .channel_slot );
1109+ if (!msg ) {
1110+ AWS_LOGF_ERROR (
1111+ AWS_LS_HTTP_CONNECTION ,
1112+ "id=%p: Failed to acquire message from pool, error %d (%s). Closing connection." ,
1113+ (void * )& connection -> base ,
1114+ aws_last_error (),
1115+ aws_error_name (aws_last_error ()));
1116+ goto error ;
1117+ }
11121118 }
11131119
11141120 /* Set up callback so we can send another message when this one completes */
@@ -1133,7 +1139,7 @@ static void s_write_outgoing_stream(struct aws_h1_connection *connection, bool f
11331139 return ;
11341140 }
11351141
1136- if (msg -> message_data .len > 0 ) {
1142+ if (msg -> message_data .len > 0 && connection -> thread_data . encoder . state != AWS_H1_ENCODER_STATE_ASYNC_WAITING ) {
11371143 AWS_LOGF_TRACE (
11381144 AWS_LS_HTTP_CONNECTION ,
11391145 "id=%p: Outgoing stream task is sending message of size %zu." ,
@@ -1155,7 +1161,16 @@ static void s_write_outgoing_stream(struct aws_h1_connection *connection, bool f
11551161 AWS_LS_HTTP_CONNECTION ,
11561162 "id=%p: Outgoing async stream task is either complete or waiting on future. Never reschedule task." ,
11571163 (void * )& connection -> base );
1158- aws_mem_release (msg -> allocator , msg );
1164+
1165+ if (connection -> thread_data .encoder .state == AWS_H1_ENCODER_STATE_ASYNC_WAITING ){
1166+ connection -> thread_data .pending_async_message = msg ;
1167+ } else {
1168+ if (msg -> message_data .len > 0 ) {
1169+ aws_channel_slot_send_message (connection -> base .channel_slot , msg , AWS_CHANNEL_DIR_WRITE );
1170+ } else {
1171+ aws_mem_release (msg -> allocator , msg );
1172+ }
1173+ }
11591174 connection -> thread_data .is_outgoing_stream_task_active = false;
11601175 } else {
11611176 /* If message is empty, warn that no work is being done
@@ -1672,17 +1687,22 @@ static void s_handler_destroy(struct aws_channel_handler *handler) {
16721687 struct aws_h1_connection * connection = handler -> impl ;
16731688
16741689 AWS_LOGF_TRACE (AWS_LS_HTTP_CONNECTION , "id=%p: Destroying connection." , (void * )& connection -> base );
1690+ AWS_LOGF_TRACE (AWS_LS_HTTP_CONNECTION , "id=%p: Hello darkness my old friend." , (void * )& connection -> base );
16751691
16761692 AWS_ASSERT (aws_linked_list_empty (& connection -> thread_data .stream_list ));
16771693 AWS_ASSERT (aws_linked_list_empty (& connection -> synced_data .new_client_stream_list ));
16781694
16791695 /* Clean up any buffered read messages. */
16801696 while (!aws_linked_list_empty (& connection -> thread_data .read_buffer .messages )) {
1697+ AWS_LOGF_TRACE (AWS_LS_HTTP_CONNECTION , "id=%p: Destroying Linked List." , (void * )& connection -> base );
16811698 struct aws_linked_list_node * node = aws_linked_list_pop_front (& connection -> thread_data .read_buffer .messages );
16821699 struct aws_io_message * msg = AWS_CONTAINER_OF (node , struct aws_io_message , queueing_handle );
16831700 aws_mem_release (msg -> allocator , msg );
16841701 }
16851702
1703+
1704+ AWS_LOGF_TRACE (AWS_LS_HTTP_CONNECTION , "id=%p: Hello darkness my old friend." , (void * )& connection -> base );
1705+
16861706 aws_h1_decoder_destroy (connection -> thread_data .incoming_stream_decoder );
16871707 aws_h1_encoder_clean_up (& connection -> thread_data .encoder );
16881708 aws_mutex_clean_up (& connection -> synced_data .lock );
0 commit comments