Skip to content

Commit

Permalink
update callback order to aovid mqtt3 client callback race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Aug 15, 2023
1 parent a2ee9a3 commit d891ebe
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions source/v5/mqtt5_to_mqtt3_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ static int s_aws_mqtt5_to_mqtt3_adapter_safe_lifecycle_handler(
(void *)adapter,
(int)adapter->adapter_state);

if (adapter->on_closed) {
(*adapter->on_closed)(&adapter->base, NULL, adapter->on_closed_user_data);
}

/* If an MQTT311-view user is waiting on a disconnect callback, invoke it */
if (adapter->on_disconnect) {
(*adapter->on_disconnect)(&adapter->base, adapter->on_disconnect_user_data);
Expand All @@ -560,10 +564,6 @@ static int s_aws_mqtt5_to_mqtt3_adapter_safe_lifecycle_handler(
adapter->on_disconnect_user_data = NULL;
}

if (adapter->on_closed) {
(*adapter->on_closed)(&adapter->base, NULL, adapter->on_closed_user_data);
}

/*
* Judgement call: If the mqtt5 client is stopped behind our back, it seems better to transition to the
* disconnected state (which only requires a connect() to restart) then stay in the STAY_CONNECTED state
Expand Down Expand Up @@ -650,13 +650,12 @@ static int s_aws_mqtt5_to_mqtt3_adapter_safe_disconnect_handler(
}

if (invoke_callbacks) {
if (disconnect_task->on_disconnect != NULL) {
(*disconnect_task->on_disconnect)(&adapter->base, disconnect_task->on_disconnect_user_data);
}

if (adapter->on_closed) {
(*adapter->on_closed)(&adapter->base, NULL, adapter->on_closed_user_data);
}
if (disconnect_task->on_disconnect != NULL) {
(*disconnect_task->on_disconnect)(&adapter->base, disconnect_task->on_disconnect_user_data);
}
}

return AWS_OP_SUCCESS;
Expand Down

0 comments on commit d891ebe

Please sign in to comment.