Skip to content

Commit 2d7a9f0

Browse files
committed
my first deadlock
1 parent 2f69171 commit 2d7a9f0

1 file changed

Lines changed: 31 additions & 28 deletions

File tree

source/h1_stream.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static int s_stream_write_data(
375375
struct aws_h1_stream *stream = AWS_CONTAINER_OF(stream_base, struct aws_h1_stream, base);
376376

377377
bool should_schedule_task = false;
378+
bool is_chunked = false;
378379

379380

380381
{ /* BEGIN CRITICAL SECTION */
@@ -406,35 +407,9 @@ static int s_stream_write_data(
406407
goto error;
407408
}
408409

409-
bool is_chunked = stream->synced_data.using_chunked_encoding;
410+
is_chunked = stream->synced_data.using_chunked_encoding;
410411

411-
if (is_chunked) {
412-
int64_t data_len = 0;
413-
if (aws_input_stream_get_length(options->data, &data_len)) {
414-
AWS_LOGF_ERROR(
415-
AWS_LS_HTTP_STREAM,
416-
"id=%p: Failed to get data stream length for chunked conversion",
417-
(void *)stream_base);
418-
goto error;
419-
}
420-
421-
struct aws_http1_chunk_options chunk_opts = {
422-
.chunk_data = options->data,
423-
.chunk_data_size = (uint64_t) data_len,
424-
.on_complete = options->on_complete,
425-
.user_data = options->user_data,
426-
};
427-
428-
if(!aws_http1_stream_write_chunk(stream_base, &chunk_opts)) {
429-
AWS_LOGF_ERROR(
430-
AWS_LS_HTTP_STREAM,
431-
"id=%p: Failed to write chunk to stream, error %d (%s).",
432-
(void *)stream_base,
433-
aws_last_error(),
434-
aws_error_name(aws_last_error()));
435-
goto error;
436-
}
437-
} else {
412+
if (!is_chunked) {
438413
struct aws_h1_data_write *data_write = aws_h1_data_write_new(stream_base->alloc, options);
439414
if (!data_write) {
440415
AWS_LOGF_ERROR(
@@ -456,6 +431,34 @@ static int s_stream_write_data(
456431
s_stream_unlock_synced_data(stream);
457432
} /* END CRITICAL SECTION */
458433

434+
if (is_chunked) {
435+
int64_t data_len = 0;
436+
if (aws_input_stream_get_length(options->data, &data_len)) {
437+
AWS_LOGF_ERROR(
438+
AWS_LS_HTTP_STREAM,
439+
"id=%p: Failed to get data stream length for chunked conversion",
440+
(void *)stream_base);
441+
goto error;
442+
}
443+
444+
struct aws_http1_chunk_options chunk_opts = {
445+
.chunk_data = options->data,
446+
.chunk_data_size = (uint64_t) data_len,
447+
.on_complete = options->on_complete,
448+
.user_data = options->user_data,
449+
};
450+
451+
if(aws_http1_stream_write_chunk(stream_base, &chunk_opts)) {
452+
AWS_LOGF_ERROR(
453+
AWS_LS_HTTP_STREAM,
454+
"id=%p: Failed to write chunk to stream, error %d (%s).",
455+
(void *)stream_base,
456+
aws_last_error(),
457+
aws_error_name(aws_last_error()));
458+
goto error;
459+
}
460+
}
461+
459462
if (should_schedule_task) {
460463
aws_atomic_fetch_add(&stream->base.refcount, 1);
461464
AWS_LOGF_TRACE(AWS_LS_HTTP_STREAM, "id=%p: Scheduling stream cross-thread work task.", (void *)stream_base);

0 commit comments

Comments
 (0)