Skip to content

fix(folders): honour folder_N_refresh instead of walking every cycle - #3676

Merged
nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/folder-refresh-timer-index
Aug 26, 2026
Merged

nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/folder-refresh-timer-index

Conversation

@ntdatt812

Copy link
Copy Markdown
Contributor

The bug

FolderList.update() guards the per-folder timer like this:

if not self.first_grab and i in self.timer_folders and not self.timer_folders[i].finished():
    continue

i is a list index; self.timer_folders is a list of Timer objects. i in self.timer_folders is a membership test, not a bounds check — it asks whether the integer i equals one of the timers. Timer doesn't implement __eq__, so it is always False:

>>> from glances.timer import Timer
>>> 0 in [Timer(600), Timer(600)]
False

So the skip branch is unreachable, and the self.timer_folders[i].reset() below it never runs either.

What it costs

folder_N_refresh has no effect. Every monitored folder is re-walked on every refresh cycle (2s by default) instead of on its own schedule — and folder_size() is a full recursive walk, which is the whole reason the setting exists.

Measured with folder_1_refresh=600 and folder_size counted:

walks after 4 update cycles
before 4
after 1

The fix

Use the bound the code meant: i < len(self.timer_folders).

The guard is worth keeping rather than dropping — __folder_list is a class attribute while timer_folders is per-instance, so the folder list can outgrow the timer list and the index has to be checked.

Tests

tests/test_folder_list_refresh.py, 4 cases: refresh delay honoured, folder walked again once the timer is over, timer restarted after a walk, and a folder with no timer still updated.

Mutation-checked — putting i in self.timer_folders back turns 2 of the 4 red:

FAILED test_folder_is_not_walked_again_before_its_refresh_delay
FAILED test_the_timer_is_restarted_after_a_walk
2 failed, 2 passed

ruff check and ruff format --check clean on both files.

update() guarded the per-folder timer with `i in self.timer_folders`,
which asks whether the integer i is one of the Timer objects in the list.
Timer does not implement __eq__, so that test is always False: the skip
branch was unreachable and the reset branch never ran.

The consequence is that folder_N_refresh has no effect. Every folder is
re-walked on every refresh cycle (2s by default) rather than on its own
schedule, and folder_size() is a full recursive walk - which is exactly
why the setting exists.

Use the index bound the code meant, `i < len(self.timer_folders)`. The
guard still earns its place: the folder list lives on the class, so it
can outgrow the per-instance timer list.
@nicolargo

Copy link
Copy Markdown
Owner

Thanks for the PR @ntdatt812

This one is tricky !

Merged into develop.

@nicolargo nicolargo added this to the Glances 4.5.7 milestone Aug 26, 2026
@nicolargo
nicolargo merged commit aa42f0f into nicolargo:develop Aug 26, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants