coreMQTT: No ack found for packet id #

I am using coreMQTT v2.1.1 and coreMQTT-Agent V1.2.
After a running for a long time, these messages accumulate:

I (146451442) network: Attempting to connect to MQTT
I (146450881) hmqtt: Connected to MQTT.
I (146450882) hmqtt: Session present.
E (146450882) coreMQTT: No ack found for packet id 15788.
E (146450886) coreMQTT: No ack found for packet id 16425.
E (146450893) coreMQTT: No ack found for packet id 60272.
E (146450899) coreMQTT: No ack found for packet id 26707.
E (146450905) coreMQTT: No ack found for packet id 28396.
E (146450912) coreMQTT: No ack found for packet id 49384.
E (146450918) coreMQTT: No ack found for packet id 49987.
E (146450925) coreMQTT: No ack found for packet id 62338.
E (146450931) coreMQTT: No ack found for packet id 43880.
E (146450938) coreMQTT: No ack found for packet id 34763.
I (146450944) hmqtt: Session resumed.
I (146451992) network: ConnectToMQTT succeeded
I (146450954) hmqtt: Waiting for network to be ready...
I (146450960) network: Subscribing to MQTT topics ...

This only happens on some devices, some of the time.
What is the cause of this issue? Is it due to maintaining the session across reconnects?
I am worried that after a while this would lead to some MqttNoMemory errors.

The log comes from this line - https://github.com/FreeRTOS/coreMQTT-Agent/blob/main/source/core_mqtt_agent.c#L415

It indicates that you are getting some ACKs on session resumption for which there is no packet waiting to be ACKed. The possible reasons are -

  • You could not store the packet because pPendingAcks array was full.
  • These are duplicate ACKs.

In either case, these will not exhaust memory.

In either case, these will not exhaust memory.

This is not true, once the number of packets reaches MQTT_AGENT_MAX_OUTSTANDING_ACKS, MQTTAgent_CommandLoop() will keep exiting with MQTTNoMemory and there is no mechanism for clearing it out other than re-initialising a clean session.

Hello @BogdanTheGeek,

You are correct in saying when the number of outstanding packets which have NOT been ACKed reach MQTT_AGENT_MAX_OUTSTANDING_ACKS, the command loop will exit with the error MQTTNoMemory. The key point is that ONLY packets which are NOT ACKed will cause this.

In your case, you are getting ACKs for packets which have already been ACKed (or maybe never sent?) and do not exist in the array. Thus, even if you keep receiving the ACKs, it will NOT cause the array to fill up.

The packets which are stored in the array will be ACKed by the broker whereafter they shall be removed from the array and the memory would be freed. If the broker doesn’t ACK the packets, then only you will run out of space in the array.

Thus, @aggarg is correct in saying that getting unsolicited/duplicate ACKs will not fill up the memory. Not getting any ACKs will!

I hope this answers your query. If I did not quite understand your point or have missed something, please feel free to chime back and we will gladly help you out!

If you think that this is surely a bug and would like to open a detailed issue, we welcome you to open a ticket on the MQTT-Agent repository here.

Thanks,
Aniruddha

1 Like