-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
[BUG] Cannot access memory #166
Comments
Low memory issue I suspect. Your application is able to handle failure to publish? (publish returns zero) PS Arduino is currently at v 3.0.5 so I don't know what you mean with 6.0.7 |
Still the same problem as #164. |
3 hypothesis:
|
you're right, same issue as in #164 |
Keep this open. The other one is converted to a discussion. It is most strange. The library allocates the entire packet on heap memory and only releases the memory after it is completely sent. Sending in this case means passed to Arduino's I'm searching for a concurrency/deadlock issue. |
Are you using builtin WiFi or an ethernet adapter (w5500)? |
Other observations: |
In this scenario here: yes
I'll give it a try. Never thought in this direction. |
This is going to be trial and error bughunting. Or somebody needs to have a divine intervention. |
All MqTT and AsyncWebserver stuff is based on AsyncTCP. Don't know if it really makes sense to disable it. The system is then not "useful" anymore. The issue does not occur on my system, it happens to one of the users on a really random pattern of days. |
To rule out memory exhaustion issues you could try with the memory pool enabled. The library then allocates its memory statically on initialization (underlying libraries not taken into account). If you need some guidance with that, let me know. |
Today I have the same issue again. From that I read a bit about I don't know too much about that but on the other hand I think these extra conditions will improve. In the meantime I try to patch the library locally and test it a few days. Hopefully it helps to cover this problem. |
quick'n'dirty: semaphore.patchdiff --git a/src/MqttClient.cpp b/src/MqttClient.cpp
index dc21f74..d4b35c4 100644
--- a/src/MqttClient.cpp
+++ b/src/MqttClient.cpp
@@ -1,7 +1,7 @@
/*
Copyright (c) 2022 Bert Melis. All rights reserved.
-This work is licensed under the terms of the MIT license.
+This work is licensed under the terms of the MIT license.
For a copy, see <https://opensource.org/licenses/MIT> or
the LICENSE file.
*/
@@ -148,16 +148,19 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, const
#endif
return 0;
}
- EMC_SEMAPHORE_TAKE();
- uint16_t packetId = (qos > 0) ? _getNextPacketId() : 1;
- if (!_addPacket(packetId, topic, payload, length, qos, retain)) {
- emc_log_e("Could not create PUBLISH packet");
+ uint16_t packetId = 0;
+ if(pdTRUE == EMC_SEMAPHORE_TAKE()) {
+ packetId = (qos > 0) ? _getNextPacketId() : 1;
+ if (!_addPacket(packetId, topic, payload, length, qos, retain)) {
+ emc_log_e("Could not create PUBLISH packet");
+ EMC_SEMAPHORE_GIVE();
+ _onError(packetId, Error::OUT_OF_MEMORY);
+ if(pdTRUE == EMC_SEMAPHORE_TAKE())
+ packetId = 0;
+ }
EMC_SEMAPHORE_GIVE();
- _onError(packetId, Error::OUT_OF_MEMORY);
- EMC_SEMAPHORE_TAKE();
- packetId = 0;
+ yield();
}
- EMC_SEMAPHORE_GIVE();
return packetId;
}
@@ -174,16 +177,19 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, espMqt
#endif
return 0;
}
- EMC_SEMAPHORE_TAKE();
- uint16_t packetId = (qos > 0) ? _getNextPacketId() : 1;
- if (!_addPacket(packetId, topic, callback, length, qos, retain)) {
- emc_log_e("Could not create PUBLISH packet");
+ uint16_t packetId = 0;
+ if(pdTRUE == EMC_SEMAPHORE_TAKE()) {
+ packetId = (qos > 0) ? _getNextPacketId() : 1;
+ if (!_addPacket(packetId, topic, callback, length, qos, retain)) {
+ emc_log_e("Could not create PUBLISH packet");
+ EMC_SEMAPHORE_GIVE();
+ _onError(packetId, Error::OUT_OF_MEMORY);
+ if(pdTRUE == EMC_SEMAPHORE_TAKE())
+ packetId = 0;
+ }
EMC_SEMAPHORE_GIVE();
- _onError(packetId, Error::OUT_OF_MEMORY);
- EMC_SEMAPHORE_TAKE();
- packetId = 0;
+ yield();
}
- EMC_SEMAPHORE_GIVE();
return packetId;
}
@@ -237,11 +243,13 @@ void MqttClient::loop() {
case State::connectingMqtt:
#if EMC_WAIT_FOR_CONNACK
if (_transport->connected()) {
- EMC_SEMAPHORE_TAKE();
- _sendPacket();
- _checkIncoming();
- _checkPing();
- EMC_SEMAPHORE_GIVE();
+ if(pdTRUE == EMC_SEMAPHORE_TAKE()) {
+ _sendPacket();
+ _checkIncoming();
+ _checkPing();
+ EMC_SEMAPHORE_GIVE();
+ yield();
+ }
} else {
_setState(State::disconnectingTcp1);
_disconnectReason = DisconnectReason::TCP_DISCONNECTED;
|
Patch which also is compatible with ESP8266 |
Regarding the return value of Every iteration of Another possibility would be to not use blocking semaphores in the library |
sure, here are the links I visited yesterday: I also asked ChatGPT (in German), this was the important output:
|
Question: do you use tasks other than the Arduino task itself in your application? You might want to disable the separate MQTT task and just call |
Describe the bug
ESP crashed, coredump was read from the device
Which platform, esp8266 or esp32? ESP32-S3
Do you use TLS or not? no TLS
Do you use an IDE (Arduino, Platformio...)? Platformio
Which version of the Arduino framework? 6.7.0
Please include any debug output and/or decoded stack trace if applicable.
Stack trace
Expected behaviour
no crash
To Reproduce
not that easy - don't know how to do it.
Additional context
Can you determine where to search? Does it happen in the MqTT library or in my code? For me it feels that the issue happens while the library publishes the internal queue.
The text was updated successfully, but these errors were encountered: