mesh: Fix postponing storage deadline indefinitely
If the local node keeps getting bombarded with messages, it's possible
that the storage timer gets rescheduled over and over again and never
expires. Add the necessary code to only reschedule the timer if the
new deadline is earlier than an existing one.
@@ -832,7 +832,7 @@ static int mesh_commit(void)
static void schedule_store(int flag)
{
- s32_t timeout;
+ s32_t timeout, remaining;
atomic_set_bit(bt_mesh.flags, flag);
@@ -847,6 +847,12 @@ static void schedule_store(int flag)
timeout = K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT);
}
+ remaining = k_delayed_work_remaining_get(&pending_store);
+ if (remaining && remaining < timeout) {
+ BT_DBG("Not rescheduling due to existing earlier deadline");
+ return;
+ }
+
BT_DBG("Waiting %d seconds", (int) (timeout / MSEC_PER_SEC));
k_delayed_work_submit(&pending_store, timeout);
