Skip to content

fix: infinite loop spikes CPU at midnight#1858

Merged
claudiux merged 1 commit into
linuxmint:masterfrom
abdelhalim97:abdelhalim97/fix-midnight-loop
Jul 6, 2026
Merged

fix: infinite loop spikes CPU at midnight#1858
claudiux merged 1 commit into
linuxmint:masterfrom
abdelhalim97:abdelhalim97/fix-midnight-loop

Conversation

@abdelhalim97

Copy link
Copy Markdown
Contributor

closes #1547

Root cause

setupUI calls refresh.
refresh set a timer to call setupUI every 1 second.
This resulted infinite loop.

At midnight this gets worst, because date changes, which will trigger calculatePrayerTimes and calculatePrayerTimes also calls setupUI...
Multiple infinite loops explains cpu spike at midnight.

Fix

Replaced refresh with a function startUpdateTimer that run once per second.
Added updateCountdown checks if day changed and recalculate prayer times at midnight.
UI will only be built when needed instead of every second

Same features without infinite loops

@github-actions

Copy link
Copy Markdown

Best-practices scanner

This is a regex-based check for API usage that can pose security, performance or
maintainability issues, or that may already be provided by Cinnamon. Most findings
are advisory and do not automatically disqualify a pull request.

This check is not perfect and will not replace a normal review.


Found 1 potential issue(s):

⚠️ WARNING

⚠️ lang_bind

prayertimes@linworx.org/files/prayertimes@linworx.org/5.8/desklet.js:175

this._timeoutId = Mainloop.timeout_add_seconds(1, Lang.bind(this, this.updateCountdown));

Lang.bind() is deprecated. Use arrow functions (() => {}) or Function.prototype.bind() instead.


Automated pattern check.

@abdelhalim97 abdelhalim97 force-pushed the abdelhalim97/fix-midnight-loop branch from 04c605b to 7f65f5f Compare June 19, 2026 23:25
@abdelhalim97 abdelhalim97 changed the title fix: infinite loop at midnight fix: infinite loop spikes CPU at midnight Jun 19, 2026
@M-Hassand

M-Hassand commented Jul 6, 2026

Copy link
Copy Markdown

Great work!

In case the original author does not wish to change the original design, it is worth noting that removing the call to setupUI at the end of calculatePrayerTimes solves the problem as well (although of course, not as elegantly as the one above).

It is not needed as before the calculatePrayerTimes call, a call to setupUI was already scheduled. This way, there's only one loop that goes back and forth between setupUI and refresh rather than multiple loops spawning at midnight.

@claudiux claudiux merged commit ba1c317 into linuxmint:master Jul 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desklet freezes entire pc daily at 12am

3 participants