Skip to content

Commit 0171ea0

Browse files
committed
Add workaround for stuck HAP server blocking updates forever
Wait 10 seconds, then proceed with the update anyway
1 parent d840bf8 commit 0171ea0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/shelly_main.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ static void SetupButton(int pin, bool on_value) {
744744
}
745745

746746
static void OTABeginCB(int ev, void *ev_data, void *userdata) {
747+
static double s_wait_start = 0;
747748
struct mgos_ota_begin_arg *arg = (struct mgos_ota_begin_arg *) ev_data;
748749
// Some other callback objected.
749750
if (arg->result != MGOS_UPD_OK) return;
@@ -760,11 +761,22 @@ static void OTABeginCB(int ev, void *ev_data, void *userdata) {
760761
return;
761762
}
762763
// Stop the HAP server.
764+
if (!(s_service_flags & SHELLY_SERVICE_FLAG_UPDATE)) {
765+
s_wait_start = mgos_uptime();
766+
}
763767
s_service_flags |= SHELLY_SERVICE_FLAG_UPDATE;
764768
if (HAPAccessoryServerGetState(&s_server) != kHAPAccessoryServerState_Idle) {
765-
arg->result = MGOS_UPD_WAIT;
766-
StopService();
767-
return;
769+
// There is a bug in HAP server where it will get stuck and fail to shut
770+
// down reported to happen after approximately 25 days. This is a workaround
771+
// until it's fixed.
772+
if (mgos_uptime() - s_wait_start > 10) {
773+
LOG(LL_WARN,
774+
("Server failed to stop, proceeding with the update anyway"));
775+
} else {
776+
arg->result = MGOS_UPD_WAIT;
777+
StopService();
778+
return;
779+
}
768780
}
769781
LOG(LL_INFO, ("Starting firmware update"));
770782
(void) ev;

0 commit comments

Comments
 (0)