alexCajas / EmbeddedMqttBroker

This is a Mqtt broker for embedded devices, developed in C++, FreeRTOS to use advanced multitasking capabilities, and arduino core. Tested in an Esp32 and esp8266.
https://github.com/alexCajas/EmbeddedMqttBroker
MIT License
71 stars 14 forks source link

It freezes after a few hours of operation #8

Closed techcom2 closed 8 months ago

techcom2 commented 1 year ago

Example simpleMqttBroker.ino sketch Two clients broadcast every 20 seconds, hangs after a few hours of work.

17:17:30.581 -> publishing: 1234/stan 17:17:30.581 -> enviando publish 17:17:39.364 -> sending ping response packet 17:17:45.727 -> publishing: 1234/stan 17:17:45.727 -> enviando publish 17:18:01.748 -> deleting client 17:18:04.958 -> deleting client 17:22:51.416 -> new client 17:22:51.416 -> 2 17:22:51.416 -> # 17:22:59.981 -> new client 17:22:59.981 -> 3 17:23:45.044 -> new client 17:23:45.044 -> 4 17:23:51.613 -> sending ping response packet 17:24:30.122 -> new client 17:24:30.122 -> 5 17:24:51.605 -> sending ping response packet 17:25:51.636 -> sending ping response packet 17:26:52.606 -> deleting client

alexCajas commented 1 year ago

Hi! @techcom2 can you get some more information? like: some memory issue, clients still connected after broker stop to print ?? I trying to reproduce the issue but I can't now. The clients are desktop software or some esp device?

techcom2 commented 1 year ago

Hello, 2 customers -0 is PC MQTT Explorer (receiving only) -1 is ESP8266 sending packet every 10s I added in the main loop: `unsigned long currentTime = millis();

if (currentTime - previousTime >= eventInterval) { Serial.println(ESP.getFreeHeap()); previousTime = currentTime; }` eventInterval = 10s. start stop

alexCajas commented 1 year ago

@techcom2 hi!, there is available new version of this library, can you test the issue again please? in this case, enable core debug level to verbose, and let me see the outputs, I tested the broker for some days with no error: 2 costommers:

sramrajkar commented 1 year ago

I can confirm that current master version of this lib is leaking memory as shows in the above picture. I have 5 clients each reporting every 1 sec. I can confirm by using them or just one PC client that on every message being published the broker leaks memory. I can also confirm the issue is not in the function where the broker finds all subscriptions and forwards them to the clients.

cavefire commented 10 months ago

I can also confirm that. In my tests 15 clients connect, each sending one message per second. After about 2000 messages it stops responding.

Adding a free(publishMessage) after calling notifyPublishReceivedCallback in https://github.com/alexCajas/EmbeddedMqttBroker/blob/70c596b8f756a3d6fec768feaf59c415a6008f30/src/MqttClient/MqttClient.cpp#L76 seems to make a difference. Now I am up to 4000 messages in. Did anyone else find another memory leak?

alexCajas commented 10 months ago

ok thanks for you support guys. @cavefire when you send 4000 messages does the broker freeze or work fine?

alexCajas commented 8 months ago

fixed in v1.0.7-qos0.