From 2e874752e72d226c2904ad43e83cd45e6f6113a5 Mon Sep 17 00:00:00 2001 From: Badr Bacem KAABIA Date: Sat, 1 Nov 2025 10:58:08 +0100 Subject: [PATCH] Fix: Correct state transition check in MqttClient_Auth Fixes an issue in MqttClient_Auth where the logic failed to check for the correct message state before packet transmission. The 'Auth' write state transitions from MQTT_MSG_BEGIN to MQTT_MSG_HEADER after initial encoding. However, the subsequent conditional check was erroneously looking for MQTT_MSG_BEGIN. This logic error could cause the AUTH packet to stall if the function was called repeatedly, especially in a multithreaded context. This change updates the check to correctly look for the MQTT_MSG_HEADER state, ensuring the AUTH packet is reliably sent over the network. Signed-off-by: Badr Bacem KAABIA --- src/mqtt_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mqtt_client.c b/src/mqtt_client.c index 7de2e1c0..38e28b0a 100644 --- a/src/mqtt_client.c +++ b/src/mqtt_client.c @@ -2692,7 +2692,7 @@ int MqttClient_Auth(MqttClient *client, MqttAuth* auth) auth->stat.write = MQTT_MSG_HEADER; } - if (auth->stat.write == MQTT_MSG_BEGIN) { + if (auth->stat.write == MQTT_MSG_HEADER) { int xfer = client->write.len; /* Send authentication packet */