Skip to content

Pass the permit turn on when a woken waiter cannot start (#197) - #198

Merged
gnacho merged 1 commit into
mainfrom
fix/197-permit-waiter
Aug 27, 2026
Merged

Pass the permit turn on when a woken waiter cannot start (#197)#198
gnacho merged 1 commit into
mainfrom
fix/197-permit-waiter

Conversation

@gnacho

@gnacho gnacho commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Closes #197.

Problem

Since the ETag gate landed, the tray icon stays on cloud-sync forever even when every folder is idle: the aggregate reports a SyncQueued/Syncing folder that never runs (no nextcloudcmd process, ~0 CPU).

Root cause

SyncPermit::release() wakes exactly ONE waiter and assumes it will try_acquire again. But the woken scheduler's start() can bail out through an early guard (empty queue, already running, paused, offline, auth/delete gates...) without taking the permit and without waking the next waiter. The turn is swallowed: the permit sits free while every other waiter sleeps forever.

With the pre-gate full reconciliations, runs took minutes and the interleavings were rare. The ETag-skip makes runs milliseconds long, so the double-waiter scenario happens routinely: a folder that receives a second trigger while queued registers two waiters; the leftover waiter's abort strands the folders behind it in SyncQueued forever.

Fix

start() now reports a StartAttempt (Ran / Waiting / Aborted). The permit-waiter callback checks the attempt: when it aborts (nothing launched, nothing waiting), it calls permit.release() to pass the turn to the next waiter (release tolerates in_use == 0). Waiting (the scheduler re-queued itself) and Ran keep the turn, exactly as before.

Testing

New regression test aborted_permit_waiter_passes_the_turn_to_the_next_folder (three schedulers on one permit, double waiter on the middle one), red-green verified: without the propagation third never starts and the assertion fails; with it every folder ends IdleOk.

Gate: 706 tests, clippy clean, fmt applied.

@gnacho
gnacho merged commit 60c53f5 into main Aug 27, 2026
2 checks passed
@gnacho
gnacho deleted the fix/197-permit-waiter branch August 27, 2026 09:10
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.

Tray icon stays on cloud-sync forever: a permit waiter that wakes up but cannot start swallows the release

1 participant