Skip to content

fix(preview): keep the local file when losing the insert race - #63376

Merged
CarlSchwan merged 1 commit into
masterfrom
fix/preview-keep-local-file-on-race
Aug 18, 2026
Merged

fix(preview): keep the local file when losing the insert race#63376
CarlSchwan merged 1 commit into
masterfrom
fix/preview-keep-local-file-on-race

Conversation

@solracsf

@solracsf solracsf commented Aug 18, 2026

Copy link
Copy Markdown
Member

Fixes: #63348

savePreview() writes the preview file before inserting its row. When two requests generate the same preview at once, the loser hits the unique constraint and then deleted the file it had written.

On an object store that is correct: the urn embeds the preview id, so the object belongs to the losing entity alone. Locally it is not, because constructPath() keys on the file id and the preview specification and never on the preview id, so both requests write the very same path. The loser therefore deleted the file the winner had just committed a row for, leaving a preview that can never be read again.

Split the two cases behind deleteUnreferencedPreview(), which removes the stored data only when the backend keys it by preview id.

Note

I chose this over the lazy alternative, catching NotFoundException at the read and regenerating there, because that path has to re-derive $maxWidth/$maxHeight mid-loop after they've already been captured and used by calculateSize(), which is exactly the kind of retry logic that breeds bugs.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf
solracsf requested a review from a team as a code owner August 18, 2026 10:57
@solracsf
solracsf requested review from SystemKeeper, come-nc, icewind1991, leftybournes and provokateurin and removed request for a team August 18, 2026 10:57
@solracsf solracsf added this to the Nextcloud 35 milestone Aug 18, 2026
@SystemKeeper

Copy link
Copy Markdown
Contributor

Thank you!

@SystemKeeper

Copy link
Copy Markdown
Contributor

/backport to stable34

@nextcloud-bot nextcloud-bot mentioned this pull request Aug 18, 2026
@CarlSchwan
CarlSchwan enabled auto-merge August 18, 2026 14:39
@CarlSchwan
CarlSchwan merged commit 04aa4e8 into master Aug 18, 2026
228 of 231 checks passed
@CarlSchwan
CarlSchwan deleted the fix/preview-keep-local-file-on-race branch August 18, 2026 15:25
@CarlSchwan

Copy link
Copy Markdown
Member

/backport to stable33

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.

[Bug]: Preview file is deleted on unique constraint violation

3 participants