web page publish and main loop share the MQTT send queue
@Yukti007 đang làm issue này rồi.
Từ ngày 13/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug
Messages going to the MQTT broker first go into a small queue of 8 slots. The main program adds messages to it (alarm Acknowledge/Dismiss/Shelve replies and the "online" message). The Broker Console web page also adds messages when someone presses Publish. The web page runs in a separate task that can interrupt the main program at any moment, and there is no lock. Both can pick the same empty slot. Then one message is lost, or a message goes out with one sender's topic and the other sender's text.
Short Summary of the expected behavior:
Every message added to the MQTT queue is sent once, on the right topic, with the right text, no matter which part of the program added it.
Short Summary of the buggy behavior:
If the web page and the main program add a message at the same moment, one message can be lost, or the topic and the text can come from different messages. The web page can still say "published".
To Reproduce
Found by reading the code. Not yet tested on a real Krake board. The two writes must overlap within microseconds, so this is hard to make happen on purpose. Suggested steps to try:
- Connect the Krake to Wi-Fi and an MQTT broker. Subscribe to its ACK topic and to a Broker Console publish topic with an MQTT client.
- Open the Broker Console web page on the Krake.
- Use a script to send many POST requests to
/broker-console/publishvery quickly. - At the same time, send alarms to the Krake and acknowledge them on the knob, or just let the "online" message go out every 10 seconds.
- See error: some messages are missing on the broker, or an ACK-topic message arrives on the Broker Console topic (or the other way round).
Expected behavior
All messages arrive at the broker, each on its own topic with its own text. An operator's Acknowledge is never lost.
Screenshots
None. Not yet tested on hardware.
Hardware description
Model: Krake (GPAD_API firmware), checked against main at commit b6ea4b3 (2026-09-20)
Serial Number: N/A (found by reading the code)
Other: Affects any Krake with Wi-Fi/MQTT and the web page in use.
Test Equipment
Model: N/A (not yet tested)
Serial Number: N/A
Additional context
Where in the code:
- The queue and the function that adds to it:
Firmware/GPAD_API/GPAD_API/mqtt_handler.cpplines 30–55
https://github.com/PubInv/krake/blob/b6ea4b3eaf0e93a580cad7cdc9f8c1541860ff06/Firmware/GPAD_API/GPAD_API/mqtt_handler.cpp#L30-L55 - Sending from the queue (in
loop()):mqtt_handler.cpplines 57–77
https://github.com/PubInv/krake/blob/b6ea4b3eaf0e93a580cad7cdc9f8c1541860ff06/Firmware/GPAD_API/GPAD_API/mqtt_handler.cpp#L57-L77 - The web page handler that adds to the queue (runs in the async web server's task):
GPAD_API.inolines 2175–2225 (thequeueMqttcall is at line 2203)
https://github.com/PubInv/krake/blob/b6ea4b3eaf0e93a580cad7cdc9f8c1541860ff06/Firmware/GPAD_API/GPAD_API/GPAD_API.ino#L2175-L2225 - Main-loop code that adds to the queue:
GPAD_API.inoline 397 ("online" message every 10 seconds) and line 575 ("online" message on broker connect);GPAD_menu.cpplines 63, 78, 92 and 118 (Acknowledge/Dismiss/Shelve/Complete)
https://github.com/PubInv/krake/blob/b6ea4b3eaf0e93a580cad7cdc9f8c1541860ff06/Firmware/GPAD_API/GPAD_API/GPAD_menu.cpp#L63 - The same pattern in the SPI mirror queue, which
queueMqtt()also fills:spi_broker_mirror.cpplines 50–70
https://github.com/PubInv/krake/blob/b6ea4b3eaf0e93a580cad7cdc9f8c1541860ff06/Firmware/GPAD_API/GPAD_API/spi_broker_mirror.cpp#L50-L70
Why it happens: queueMqtt() finds an empty slot, copies in the topic, then the text, and only then marks the slot as used. The web task can interrupt in the middle of that, see the same slot as empty, and write into it too. There is no mutex, critical section or FreeRTOS queue: a search of the firmware for mutex, Semaphore, portENTER_CRITICAL and xQueue finds nothing.
How likely: low. The two writes must overlap within microseconds. But it happens at random, cannot be reproduced on demand, and a lost Acknowledge matters on an alarm device.
Possible fix: protect queueMqtt() and serviceMqttQueue() (and the matching SPI mirror functions) with a FreeRTOS mutex or a short critical section. Or have the web handler pass the message to the main loop through a FreeRTOS queue, so only loop() touches the MQTT queue. The same handler also changes saved publish topics and settings from the web task (lines 2204–2221), so the fix should cover those too.
Not checked: the async web server library is not listed in platformio.ini, so its exact task priority and core setting could not be confirmed from this repo.
Related: #370 (MQTT messages published), #283 (shared global variables).
- Ngôn ngữ chính
- C++
- Star
- 9
- Fork
- 6
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PubInv/krake
-
USB and COM port share one command bufferCó thể đã có người làm @Yukti007 đã nhận 3 ngày trước. Đang mởHigh Priority
-
Firmware, Krake Loosing Broker Settings back to a DefaultCó thể đã có người làm @nk25719 đã nhận 16 ngày trước. Đang mở
-
Hardware, LB0007 Not Playing Alarm FileCó thể đã có người làm @nk25719 đã nhận 23 ngày trước. Đang mở
-
Mini MP3 File Names and File Order For Reliable Play Back, Both GPAD_API and Factory TestCó thể đã có người làm @Yukti007 đã nhận 24 ngày trước. Đang mở
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
Issue tương tự
-
backlog bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
EchoTools/nevr-runtime#653 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
InfiniTimeOrg/InfiniTime#2492 ·
-
accessibility good first issue hacktoberfest help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
OpenChemistry/avogadrolibs#3184 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Tracktion/tracktion_engine#475 ·
Maintainer thường phản hồi trong vòng 1 ngày