Skip to content

Commit 21da363

Browse files
committed
minor bugfixes
1 parent 7f37ef3 commit 21da363

5 files changed

Lines changed: 38 additions & 12 deletions

File tree

include/aws/http/private/h1_connection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ struct aws_h1_connection {
120120
bool is_outgoing_stream_task_active : 1;
121121

122122
bool is_processing_read_messages : 1;
123+
124+
struct aws_io_message *pending_async_message;
123125
} thread_data;
124126

125127
/* Any thread may touch this data, but the lock must be held */

source/h1_connection.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

source/h1_encoder.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ int aws_h1_encoder_message_init_from_response(
430430

431431
void aws_h1_encoder_message_clean_up(struct aws_h1_encoder_message *message) {
432432
aws_input_stream_release(message->body);
433+
aws_async_input_stream_release(message->async_body);
433434
aws_byte_buf_clean_up(&message->outgoing_head_buf);
434435
aws_h1_trailer_destroy(message->trailer);
435436
AWS_ZERO_STRUCT(*message);
@@ -714,10 +715,13 @@ static void s_on_async_body_read_complete(void *user_data) {
714715

715716
bool eof = !error && aws_future_bool_get_result(encoder->pending_async_future);
716717

718+
ENCODER_LOGF(DEBUG, encoder, "Async body read complete. error=%d eof=%d", error, eof);
719+
717720
aws_future_bool_release(encoder->pending_async_future);
718721
encoder->pending_async_future = NULL;
719722

720723
if (eof) {
724+
ENCODER_LOG(DEBUG, encoder, "EOF reached, switching to DONE state");
721725
s_switch_state(encoder, AWS_H1_ENCODER_STATE_DONE);
722726
} else {
723727
ENCODER_LOG(DEBUG, encoder, "Error occurred or buffer was full but eof not reached. We have to initiate a new encode request with a new buffer.");

source/http.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ void aws_http_library_clean_up(void) {
534534
return;
535535
}
536536
s_library_initialized = false;
537-
538537
aws_thread_join_all_managed();
539538
aws_unregister_error_info(&s_error_list);
540539
aws_unregister_log_subject_info_list(&s_log_subject_list);

source/request_response.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ struct aws_http_message *aws_http_message_release(struct aws_http_message *messa
600600

601601
aws_http_headers_release(message->headers);
602602
aws_input_stream_release(message->body_stream);
603+
aws_async_input_stream_release(message->async_body_stream);
603604
aws_mem_release(message->allocator, message);
604605
} else {
605606
AWS_ASSERT(prev_refcount != 0);

0 commit comments

Comments
 (0)