Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT-C endless loop if sendbuffer is too large #190

Open
Bauteiltoeter opened this issue May 16, 2024 · 0 comments
Open

MQTT-C endless loop if sendbuffer is too large #190

Bauteiltoeter opened this issue May 16, 2024 · 0 comments

Comments

@Bauteiltoeter
Copy link

After enlarging the receive / sendBuffer for MQTT-C to 16MB my application started to go into endless loops at 100% CPU time after some time.

My application is sending and receiveing QoS0-Messages only.

Investigating this issue showed that the do-while-loop inside of __mqtt_next_pid was spinning endlessly because it couldn't find any unused pids. Analysing client->mq showed that there where 65535 packages in the queue.

I tried to find the mechanism where this queue is cleared. The only way that I could find to clear the queue is the callstack
mqtt_publish() -> MQTT_CLIENT_TRY_PACK() -> mqtt_pack_publish_request() -> mqtt_pack_fixed_header() returning 0 because there is not enough space in the transmit buffer.

This means there is no "normal" way this queue is cleared, it's only cleared if it's full. If more than 65535 packages fit into the queue it will fail.

My application has a lot of small messages mixed with very big messages, this will make the appearance of the bug much more likely.

Steps to reproduce:

  • Start with the examples/simple_publisher.c
  • Change sendbuf[] size to 0xFFFFFF (16MB)
  • Change the while()-Loop to a while(1) to make it endless
  • add a usleep(5000u) to slow it down a little bit
  • Build, start and grab a coffee
  • CPU usage will slowly increase until it will hit a 100% wall after the 65535th package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant