Skip to content

Commit 944d1e5

Browse files
committed
mimic write_chunk for cleanup behavior
1 parent 5e1f774 commit 944d1e5

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

source/h1_connection.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,10 @@ static void s_stream_complete(struct aws_h1_stream *stream, int error_code) {
710710
/* Mark stream complete */
711711
stream->synced_data.api_state = AWS_H1_STREAM_API_STATE_COMPLETE;
712712

713-
/* Move chunks out of synced data */
713+
/* Move chunks and data writes out of synced data */
714714
aws_linked_list_move_all_back(&stream->thread_data.pending_chunk_list, &stream->synced_data.pending_chunk_list);
715+
aws_linked_list_move_all_back(
716+
&stream->thread_data.pending_data_write_list, &stream->synced_data.pending_data_write_list);
715717

716718
aws_h1_connection_unlock_synced_data(connection);
717719
} /* END CRITICAL SECTION */
@@ -723,6 +725,13 @@ static void s_stream_complete(struct aws_h1_stream *stream, int error_code) {
723725
aws_h1_chunk_complete_and_destroy(chunk, &stream->base, AWS_ERROR_HTTP_STREAM_HAS_COMPLETED);
724726
}
725727

728+
/* Complete any leftover data writes */
729+
while (!aws_linked_list_empty(&stream->thread_data.pending_data_write_list)) {
730+
struct aws_linked_list_node *node = aws_linked_list_pop_front(&stream->thread_data.pending_data_write_list);
731+
struct aws_h1_data_write *data_write = AWS_CONTAINER_OF(node, struct aws_h1_data_write, node);
732+
aws_h1_data_write_complete_and_destroy(data_write, &stream->base, AWS_ERROR_HTTP_STREAM_HAS_COMPLETED);
733+
}
734+
726735
if (stream->base.on_metrics) {
727736
stream->base.on_metrics(&stream->base, &stream->base.metrics, stream->base.user_data);
728737
}

source/h1_encoder.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ static int s_encoder_state_data_write_next(struct aws_h1_encoder *encoder, struc
10361036

10371037
struct aws_linked_list_node *node = aws_linked_list_front(encoder->message->pending_data_write_list);
10381038
encoder->message->current_data_write = AWS_CONTAINER_OF(node, struct aws_h1_data_write, node);
1039-
aws_linked_list_remove(node);
10401039

10411040
ENCODER_LOG(TRACE, encoder, "Begin sending manual data write");
10421041
return s_switch_state(encoder, AWS_H1_ENCODER_STATE_DATA_WRITE_BODY);
@@ -1113,6 +1112,7 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
11131112
/* This data write is complete */
11141113
ENCODER_LOG(TRACE, encoder, "Manual data write complete");
11151114
bool is_end = data_write->is_end_stream;
1115+
aws_linked_list_remove(&data_write->node);
11161116
aws_h1_data_write_complete_and_destroy(data_write, encoder->current_stream, AWS_ERROR_SUCCESS);
11171117
encoder->message->current_data_write = NULL;
11181118

@@ -1135,6 +1135,7 @@ static int s_encoder_state_data_write_body(struct aws_h1_encoder *encoder, struc
11351135
return s_switch_state(encoder, AWS_H1_ENCODER_STATE_DATA_WRITE_NEXT);
11361136

11371137
error:
1138+
aws_linked_list_remove(&data_write->node);
11381139
aws_h1_data_write_complete_and_destroy(data_write, encoder->current_stream, error_code);
11391140
encoder->message->current_data_write = NULL;
11401141
return aws_raise_error(error_code);

0 commit comments

Comments
 (0)