Repository navigation
fix(sync): list a cached mailbox while it syncs - #14342
Open
DerDreschner wants to merge 2 commits into
Open
DerDreschner wants to merge 2 commits into
DerDreschner wants to merge 2 commits into
Conversation
Resetting the cache of a mailbox (clear cache, UIDVALIDITY change, no mod-sequence support) deleted the recipients in chunks, then the messages, and only then cleared the sync tokens, each committed on its own. In between, the mailbox still counted as cached while its messages had no sender or were gone, and a failure in between left it that way. Run the delete and the token reset in one transaction, retried on deadlocks. Clear the tokens with an explicit update instead of saving the entity: the entity setter skips values it already holds, so a mailbox loaded before a sync stored its tokens kept them while all its messages were deleted. The entity only gets the empty tokens after the commit, because unlocking saves it. Left out: JMAP's clearCache resets in the same non-atomic order. The recipients stay in the transaction; deleting them after the commit would keep it smaller for very large mailboxes, but would leave orphans to the cleanup job when it fails. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
The message list refused any mailbox with an active sync lock, so the folder showed a loading skeleton and retried every 15 s for as long as a sync ran: up to 5 minutes, or the whole sync once the locks are refreshed during long syncs (#14339). The check comes from 6d2d36a, when the initial sync still deleted the cache first; bff314c removed that three weeks later. Keep refusing mailboxes that are not cached yet, so the client waits for another process's initial sync instead of starting one too. Read the mailbox again after its messages and previews, so a cache reset committed in between returns 409 instead of an empty list. Left out: the client retries a locked sync every 1.5 s, each retry logging in to IMAP, and now gets there right after opening a folder during a sync; that retry gets its own change. A threaded list can show new messages of a running sync before their threads are built, as it already did between a mailbox's sync and the end of the account sync. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
DerDreschner
requested review from
ChristophWurst,
GretaD and
kesselb
as code owners
November 26, 2026 18:38
Member
Author
|
/backport to stable5.13 |
DerDreschner
enabled auto-merge
November 26, 2026 18:41
This branch has not been deployed
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.
Context
Ref #14341 (the silent 15 s retry while a sync holds the lock)
The message list returned 409 for any mailbox with an active sync lock. The folder showed the loading skeleton and retried every 15 s for as long as a sync ran: up to 5 minutes on main, the whole sync with #14339. The check comes from 6d2d36a, when the initial sync still deleted the cache first; bff314c removed that three weeks later.
Approach
Left out:
Testing
Unit tests for listing while locked (cached, not cached, expired lock, a reset committed while loading previews) and for the reset (commit order, UIDVALIDITY path, rollback without saving empty tokens). Mapper integration test for clearing the tokens of a stale entity on SQLite and MariaDB. Integration tests with Dovecot and Stalwart.
Dovecot, MariaDB, 20k messages:
Benchmark:
AI assistance
Assisted by ClaudeCode:claude-opus-5-5