Repository navigation
fix(federation): persist address book sync token after each page - #65941
SebastianKrupinski merged 1 commit into
Conversation
|
No backports? 😄 |
DerDreschner
left a comment
There was a problem hiding this comment.
Needs a rebase: #65224 added IAppConfig $appConfig as the fourth constructor argument of SyncFederationAddressBooks, so the two new tests fail with a TypeError on current master, even though the merge has no conflicts (inline).
Outside the diff:
SyncFederationAddressBooks.php:79: if the final token equals$oldSyncToken, nothing is written, so the last intermediate token fromsetServerSyncToken()stays stored while the status says OK. This happens on a--fullsync of a truncated address book when the remote hasn't changed: stored…/T, the pages save…/init_2500_Tand…/init_5000_T, the last page returns…/T, and…/init_5000_Tstays. The next SyncJob then downloads every card after id 5000 again. Comparing against the last saved token (e.g.$oldSyncToken = $syncTokenafter saving) would fix it.SyncFederationAddressBooks.php:90: on a 401,SyncService::syncRemoteAddressBook()deletes the local address book, but the stored intermediate token stays. Before, a first sync that hit this kept anulltoken and started over. Now, once access is restored, the sync creates an empty book and resumes frominit_<lastId>_…, so the contacts from the earlier pages are missing until a manual--full. The token should be cleared when the address book is deleted.
Assisted by ClaudeCode:claude-opus-5-5
| ->willReturnOnConsecutiveCalls(['init_1_5', true], ['init_2_5', true], ['5', false]); | ||
|
|
||
| /** @var SyncService $syncService */ | ||
| $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger); |
There was a problem hiding this comment.
After a rebase this needs $this->createMock(IAppConfig::class) before $this->logger (#65224 added IAppConfig as the fourth constructor argument). Same at line 145.
| $targetPrincipal, | ||
| $targetBookProperties | ||
| ); | ||
| if ($truncated && $syncToken !== null) { |
There was a problem hiding this comment.
With --full, saving intermediate tokens can lose remote deletions. If a full sync fails after the first page, init_2500_T is stored. The next regular SyncJob resumes the init listing, which only reports cards that still exist, and deletePendingCards() only runs with $full. Before this change, the next run synced from the old token and got the deletions from the change log.
Example: stored token T_old, the remote deletes carol's card, an admin runs occ federation:sync-addressbooks --full on a 6000-card book, page 1 saves init_2500_T, page 2 fails. The next SyncJob ends at T without seeing carol's deletion, so her card stays until another full sync succeeds.
Not saving intermediate tokens when $full is set would avoid this; a --full retry starts from null anyway.
Tests: nothing covers a truncated page with a null token or a $full sync with truncated pages, so removing the null check or saving tokens during --full keeps the tests green.
| // Keep the progress of completed pages in case a later page fails | ||
| $this->dbHandler->setServerSyncToken($url, $syncToken); | ||
| } | ||
| } while ($truncated); |
There was a problem hiding this comment.
Pre-existing, but with this PR it also writes to the DB on every pass: do … while ($truncated) never ends if the remote keeps answering truncated without moving the token forward. The remote's incremental query uses gte('synctoken', …), so with carddav_sync_request_truncation set to 1 it returns the token it was given. A null token with truncated = true loops as well. Failing the sync when the new token is null or equal to the previous one would stop it.
There was a problem hiding this comment.
This is out of scope but I fixed it because it can be a big issue.
| $this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']); | ||
| } | ||
|
|
||
| public function testSetServerSyncToken(): void { |
There was a problem hiding this comment.
With only one server in the table, this would still pass if setServerSyncToken() updated every row. A second server whose sync_token stays null would cover the url_hash condition.
d83934b to
84a8c77
Compare
|
/backport to stable35 |
|
/backport to stable34 |
|
/backport to stable33 |
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b7f46fc to
a47eea8
Compare
Summary
Checklist
3. to review, feature component)stable32)AI (if applicable)