From edfb29b406e450e6e0826009d57cc79d749756b0 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 19 Aug 2021 18:14:19 +0200 Subject: [PATCH] Fix duplicate suspend scheduling in Device:onPowerEvent We should always unschedule suspend before scheduling it again (i.e., use rescheduleSuspend ;)). Fix #8097 (many thanks to @Mel-kior for the detailed repro!) --- frontend/device/generic/device.lua | 2 +- frontend/ui/uimanager.lua | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index d316bad0b..bec361e0b 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -341,7 +341,7 @@ function Device:onPowerEvent(ev) -- Only actually schedule suspension if we're still supposed to go to sleep, -- because the Wi-Fi stuff above may have blocked for a significant amount of time... if self.screen_saver_mode then - UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend) + self:rescheduleSuspend() end end) end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index fa13cbe8a..94358d49a 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -1178,16 +1178,15 @@ function UIManager:_checkTasks() -- task.action may schedule other events self._task_queue_dirty = false while true do - local nu_task = #self._task_queue - if nu_task == 0 then - -- all tasks checked + if #self._task_queue == 0 then + -- Nothing to do! break end - local task = self._task_queue[1] - local task_tv = task.time or TimeVal.zero + local next_task = self._task_queue[1] + local task_tv = next_task.time or TimeVal.zero if task_tv <= self._now then -- remove from table - table.remove(self._task_queue, 1) + local task = table.remove(self._task_queue, 1) -- task is pending to be executed right now. do it. -- NOTE: be careful that task.action() might modify -- _task_queue here. So need to avoid race condition @@ -1195,7 +1194,7 @@ function UIManager:_checkTasks() else -- queue is sorted in ascendant order, safe to assume all items -- are future tasks for now - wait_until = task.time + wait_until = next_task.time break end end