Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S2N blocked issue #589

Merged
merged 16 commits into from
Aug 10, 2023
2 changes: 2 additions & 0 deletions include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ enum aws_io_errors {
AWS_IO_STREAM_SEEK_UNSUPPORTED,
AWS_IO_STREAM_GET_LENGTH_UNSUPPORTED,

AWS_IO_TLS_ERROR_READ_FAILURE,

AWS_IO_ERROR_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_IO_PACKAGE_ID),
AWS_IO_INVALID_FILE_HANDLE = AWS_ERROR_INVALID_FILE_HANDLE,
};
Expand Down
4 changes: 4 additions & 0 deletions source/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ static struct aws_error_info s_errors[] = {
AWS_DEFINE_ERROR_INFO_IO(
AWS_IO_STREAM_GET_LENGTH_UNSUPPORTED,
"Get length is not supported in the underlying I/O source."),
AWS_DEFINE_ERROR_INFO_IO(
AWS_IO_TLS_ERROR_READ_FAILURE,
"Failed to read during TLS"),

};
/* clang-format on */

Expand Down
18 changes: 16 additions & 2 deletions source/s2n/s2n_tls_channel_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ static int s_s2n_handler_process_read_message(
AWS_LOGF_TRACE(
AWS_LS_IO_TLS, "id=%p: Downstream window %llu", (void *)handler, (unsigned long long)downstream_window);

while (processed < downstream_window && blocked == S2N_NOT_BLOCKED) {
while (processed < downstream_window) {

struct aws_io_message *outgoing_read_message = aws_channel_acquire_message_from_pool(
slot->channel, AWS_IO_MESSAGE_APPLICATION_DATA, downstream_window - processed);
Expand Down Expand Up @@ -558,7 +558,21 @@ static int s_s2n_handler_process_read_message(

if (read < 0) {
aws_mem_release(outgoing_read_message->allocator, outgoing_read_message);
continue;

/* the socket blocked so exit from the loop */
if (s2n_error_get_type(s2n_errno) == S2N_ERR_T_BLOCKED) {
break;
}

/* the socket returned a fatal error so shut down */
AWS_LOGF_ERROR(
AWS_LS_IO_TLS,
"id=%p: S2N failed to read with error: %s (%s)",
(void *)handler,
s2n_strerror(s2n_errno, "EN"),
s2n_strerror_debug(s2n_errno, "EN"));
aws_channel_shutdown(slot->channel, AWS_IO_TLS_ERROR_READ_FAILURE);
return aws_raise_error(AWS_IO_TLS_ERROR_READ_FAILURE);
};

processed += read;
Expand Down