Skip to content

fix(session): handle session token conflicts outside of the transaction - #65276

Merged
susnux merged 1 commit into
masterfrom
carl/session-token-pgsql-race
Nov 6, 2026
Merged

susnux merged 1 commit into
masterfrom
carl/session-token-pgsql-race

Conversation

@CarlSchwan

Copy link
Copy Markdown
Member

Summary

When two concurrent requests of the same session (e.g. with Apache/SSO based login) try to create the session token, one of them fails with a unique constraint violation. The recovery path then looked up the existing token, but it ran inside the transaction opened by createSessionToken(). On PostgreSQL the failed INSERT aborts the whole transaction, so the lookup failed with "SQLSTATE[25P02]: current transaction is aborted" and the request errored out.

Move the conflict handling from Token\Manager to Session so that it runs after the transaction was rolled back.

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@CarlSchwan CarlSchwan added this to the Nextcloud 36 milestone Oct 7, 2026
@CarlSchwan CarlSchwan self-assigned this Oct 7, 2026
@CarlSchwan
CarlSchwan requested a review from a team as a code owner October 7, 2026 12:08
@CarlSchwan CarlSchwan added bug 3. to review Waiting for reviews labels Oct 7, 2026
@CarlSchwan
CarlSchwan requested review from icewind1991, leftybournes, provokateurin and salmart-dev and removed request for a team October 7, 2026 12:08

@cristianscheid cristianscheid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides small comment typo, there's a InvalidDocblock psalm error

Comment thread lib/private/User/Session.php Resolved
When two concurrent requests of the same session (e.g. with Apache/SSO
based login) try to create the session token, one of them fails with a
unique constraint violation. The recovery path then looked up the
existing token, but it ran inside the transaction opened by
createSessionToken(). On PostgreSQL the failed INSERT aborts the whole
transaction, so the lookup failed with "SQLSTATE[25P02]: current
transaction is aborted" and the request errored out.

Move the conflict handling from Token\Manager to Session so that it
runs after the transaction was rolled back.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan
CarlSchwan force-pushed the carl/session-token-pgsql-race branch from 67f45b7 to 402e575 Compare October 19, 2026 12:37
@susnux
susnux merged commit e291878 into master Nov 6, 2026
153 of 155 checks passed
@susnux
susnux deleted the carl/session-token-pgsql-race branch November 6, 2026 20:17
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 14, 2026
@alperozturk96

Copy link
Copy Markdown

/backport to stable33

@alperozturk96

Copy link
Copy Markdown

/backport to stable34

@alperozturk96

Copy link
Copy Markdown

/backport to stable35

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants