diff --git a/source/v5/mqtt5_to_mqtt3_adapter.c b/source/v5/mqtt5_to_mqtt3_adapter.c index 55b47046..bc290499 100644 --- a/source/v5/mqtt5_to_mqtt3_adapter.c +++ b/source/v5/mqtt5_to_mqtt3_adapter.c @@ -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); @@ -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 @@ -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;