Skip to content

Commit c33ec62

Browse files
committed
Do not remove a correlation token from in use when a failed operation is using the same correlation token.
1 parent c722a84 commit c33ec62

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

source/request-response/request_response_client.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ static void s_complete_request_operation_with_failure(struct aws_mqtt_rr_client_
419419

420420
s_change_operation_state(operation, AWS_MRROS_PENDING_DESTROY);
421421

422-
if (operation->storage.request_storage.options.correlation_token.len > 0) {
422+
if (operation->storage.request_storage.options.correlation_token.len > 0 &&
423+
error_code != AWS_ERROR_MQTT_REQUEST_RESPONSE_DUPLICATE_CORRELATION_TOKEN) {
423424
s_remove_correlation_token_from_in_use(operation);
424425
}
425426

tests/request-response/request_response_client_tests.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,8 @@ static int s_rrc_request_response_failure_duplicate_correlation_token_fn(struct
33293329
struct aws_rr_client_test_fixture fixture;
33303330
ASSERT_SUCCESS(s_init_fixture_request_operation_success(&fixture, &client_test_options, allocator, NULL, NULL));
33313331

3332+
// First operation will use the duplicate correlation key but won't complete the publish
3333+
// so that the token is held by the request response client.
33323334
struct aws_byte_cursor record_key = aws_byte_cursor_from_c_str("testkey");
33333335
ASSERT_SUCCESS(s_rrc_test_submit_test_request(
33343336
&fixture,
@@ -3340,6 +3342,7 @@ static int s_rrc_request_response_failure_duplicate_correlation_token_fn(struct
33403342
NULL,
33413343
false));
33423344

3345+
// Second operation is scheduled immediately following the first making it so both should be in the task manager
33433346
struct aws_byte_cursor record_key_2 = aws_byte_cursor_from_c_str("testkey2");
33443347
s_rrc_test_submit_test_request(
33453348
&fixture,
@@ -3351,14 +3354,35 @@ static int s_rrc_request_response_failure_duplicate_correlation_token_fn(struct
33513354
NULL,
33523355
false);
33533356

3357+
// The second operation will be scheduled as the correlation token is not held by the RR client yet but will
3358+
// fail with completion when the scheduled task attempts to be run.
33543359
s_rrc_wait_on_request_completion(&fixture, record_key_2);
33553360

3361+
// This task should have failed with the AWS_ERROR_MQTT_REQUEST_RESPONSE_DUPLICATE_CORRELATION_TOKEN.
33563362
struct aws_hash_element *element = NULL;
33573363
aws_hash_table_find(&fixture.request_response_records, &record_key_2, &element);
33583364
AWS_FATAL_ASSERT(element != NULL && element->value != NULL);
33593365
struct aws_rr_client_fixture_request_response_record *record = element->value;
33603366
ASSERT_INT_EQUALS(AWS_ERROR_MQTT_REQUEST_RESPONSE_DUPLICATE_CORRELATION_TOKEN, record->error_code);
33613367

3368+
// Third operation is scheduled after the second has failed meaning that the correlation key is already
3369+
// held by the RR client. This task will not be scheduled and will fail immediately when the options are
3370+
// validated.
3371+
struct aws_byte_cursor record_key_3 = aws_byte_cursor_from_c_str("testkey3");
3372+
s_rrc_test_submit_test_request(
3373+
&fixture,
3374+
RRC_PHDT_FAILURE_DUPLICATE_CORRELATION_TOKEN,
3375+
"test3",
3376+
record_key_3,
3377+
"test3/accepted",
3378+
"token1",
3379+
NULL,
3380+
false);
3381+
3382+
// The log will show that the failed option validation is a duplicate correlation token but the error that
3383+
// is raised will be AWS_ERROR_INVALID_ARGUMENT.
3384+
ASSERT_INT_EQUALS(AWS_ERROR_INVALID_ARGUMENT, aws_last_error());
3385+
33623386
s_aws_rr_client_test_fixture_clean_up(&fixture, false);
33633387

33643388
aws_mqtt_library_clean_up();

0 commit comments

Comments
 (0)