Skip to content

fix: queue clipboard cleanup only after the copy commits - #39244

Open
bmtcril wants to merge 2 commits into
masterfrom
bmtcril/fix-plat-010
Open

bmtcril wants to merge 2 commits into
masterfrom
bmtcril/fix-plat-010

Conversation

@bmtcril

@bmtcril bmtcril commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Description

Copying to the clipboard marks the user's previous StagedContent rows EXPIRED and enqueued delete_expired_clipboards from inside the request's transaction. An idle CMS worker could start the task at once and delete the expired row, which cascades to the user's UserClipboard row, while the request went on to update_or_create that same row. The two took the locks in opposite orders, MySQL killed the request with a deadlock (1213), and the copy answered 500.

Enqueue the cleanup with transaction.on_commit, and make both clipboard save functions atomic so the clipboard row is repointed at the new content before the cleanup can run, even when the caller has no transaction open.

Closes #39118

Tycho Hob and others added 2 commits October 16, 2026 17:46
Copying to the clipboard marks the user's previous StagedContent rows
EXPIRED and enqueued `delete_expired_clipboards` from inside the request's
transaction. An idle CMS worker could start the task at once and delete
the expired row, which cascades to the user's UserClipboard row, while
the request went on to `update_or_create` that same row. The two took
the locks in opposite orders, MySQL killed the request with a deadlock
(1213), and the copy answered 500.

Enqueue the cleanup with `transaction.on_commit`, and make both clipboard
save functions atomic so the clipboard row is repointed at the new
content before the cleanup can run, even when the caller has no
transaction open.

Closes #39118

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mypy rejected `list[int]` for the ids passed to the clipboard cleanup
helper: they are `StagedContent.ID`s, as `delete_expired_clipboards`
declares.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bmtcril
bmtcril force-pushed the bmtcril/fix-plat-010 branch from b95ecf8 to 6c88f50 Compare October 16, 2026 21:46

This branch has not been deployed

No deployments
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.

Bug: clipboard 500 (deadlock)

1 participant