Repository navigation
fix(sync): stop syncing twice per interval - #340
Merged
ErikBjare merged 5 commits intoOct 10, 2026
Merged
Conversation
7 of 20 tasks
|
The in-process Handler chain and the AlarmManager fallback both fired every 15 minutes, so each cycle could run two full syncs and SAF mirrors. The alarm now skips when a sync completed within the last half interval, and enqueues unique work so alarm workers can't stack. The Handler chain removes any pending runnable before reposting, so a sync completing after stop()/start() can't leave two chains running.
0xbrayo
force-pushed
the
fix/sync-dedupe-schedulers
branch
from
October 8, 2026 19:37
fd4a25f to
72351a8
Compare
Half an interval was too short: the Handler syncs every 15 minutes, so the alarm firing ~14 minutes after a Handler sync still ran a second full sync and mirror. Skip while the last pass is under one interval old, i.e. while the Handler chain is on schedule.
Member
Author
With the last completed sync of any kind as the signal, a dead service let the fallback's own sync suppress the next alarm, stretching the fallback cadence to ~30 minutes. Record the Handler chain's passes in their own preference and decide on those alone.
Member
Author
Member
Author
A Handler pass skipped because the fallback was already syncing still schedules the chain's next pass, but left the recorded time stale, so the following alarm could sync just before that pass. Record every Handler pass, synced or skipped.
0xbrayo
force-pushed
the
fix/sync-dedupe-schedulers
branch
from
October 8, 2026 20:58
7150018 to
a67f3a8
Compare
Member
Author
Member
Author
Member
Author
An alarm delivered just before a Handler pass recorded it could queue a worker that started right after that pass and synced again. Record the pass when it starts as well as when it ends, and repeat the redundancy check in SyncWorker before syncing.
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #333.
SyncSchedulerruns an in-process Handler chain every 15 minutes and also registers an AlarmManager fallback with the same 15-minute interval.syncInFlightstops the two from overlapping, but not from running back to back, so most cycles did two full syncs and two SAF mirrors.Change
SyncAlarmReceiverskips the fallback while the last sync is less than one interval old, i.e. while the Handler chain is on schedule. If the service was killed, the last sync goes stale and the alarm takes over as before.KEEP), so a slow worker from the previous alarm can't be stacked with a new one.removeCallbacks(syncRunnable)before every repost. Before, a sync that completed after astop()/start()reposted alongside the new chain and left two chains running.Testing
SyncSchedulerTestcovers the skip decision: recent sync, stale or missing sync, and a completion time in the future after a clock step../gradlew :mobile:testStandardDebugUnitTestpasses.