feat(mqtt): cooperative MQTT shutdown + OTA teardown barrier (Phase 5)
Wire the Phase 4 MQTTLifecycle state machine into MQTTBridge to replace the blind vTaskDelete teardown that could kill the MQTT task mid-mbedTLS and then free client buffers on a corrupted heap (the observed OTA teardown panic). - MQTTBridge owns a MQTTLifecycle::Coordinator driven only by the loop task (Core 1) from begin()/end(); a nested LifecycleOps binds the host-tested Ops spec to FreeRTOS/PsychicMqttClient. - end() requests a cooperative stop; the MQTT task (Core 0) tears down its own clients where the mbedTLS contexts live, acks via _stop_acked, and self-terminates. end() waits (bounded) for the ack, then frees queue/buffers. - Bounded stop timeout -> reviewed fallback (force kill + Core-1 teardown) sets a dirty latch that withholds OTA flashing. - begin() gains an idempotent double-call guard and syncs the Coordinator to Running. - OTA teardown barrier: simple_repeater's deferred flash aborts/resumes unless end() reported a clean stop (canFlashAfterStop()). Scope: minimal cooperative-shutdown unit. The volatile NTP/reconfigure handshake replacement and the plain-data snapshot / consumer repointing (MQTT_OWNERSHIP.md sections 1-3) are deferred. MQTT_STOP_TIMEOUT_MS is a Phase-0 placeholder pending on-hardware characterization. Native suite green (incl. test_mqtt_lifecycle); both observer firmware smoke builds compile. Not yet hardware-validated (Phase 7 gate).
This commit is contained in:
1 parent
9d5bd6f898
commit
2e1a1410ce
5 files changed
+292
-76
No files matched your search
@@ -1569,7 +1569,14 @@ void MyMesh::loop() {
|
||||
Serial.println("OTA: starting update");
|
||||
setBridgeState(false);
|
||||
char ota_reply[160];
|
||||
if (!_cli.getBoard()->otaFromManifest(getFirmwareVer(), false, ota_reply)) {
|
||||
// OTA teardown barrier (Phase 5): only flash after a CLEAN MQTT shutdown.
|
||||
// A timed-out/forced stop leaves mbedTLS/heap ownership uncertain — writing
|
||||
// firmware then is the observed teardown heap-panic path — so abort and
|
||||
// resume the bridge instead of flashing under uncertain ownership.
|
||||
if (bridge && !bridge->canFlashAfterStop()) {
|
||||
Serial.println("OTA: aborted, MQTT stop did not complete cleanly - resuming bridge");
|
||||
setBridgeState(true);
|
||||
} else if (!_cli.getBoard()->otaFromManifest(getFirmwareVer(), false, ota_reply)) {
|
||||
Serial.print("OTA: aborted, resuming bridge - "); Serial.println(ota_reply);
|
||||
setBridgeState(true);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user