Skip to content

Conversation

@ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Oct 2, 2022

The session token renewal does

  1. Read the old token
  2. Write a new token
  3. Delete the old token

If two processes succeed to read the old token there can be two new tokens because the queries were not run in a transaction. This is particularly problematic on clustered DBs where 1) would go to a read node and 2) and 3) go to a write node.

Wrapping this code in a transaction makes sure that it all goes through or the insert/delete never happen, as it should.

This problem came up in a discussion with @rullzer.

This is best reviewed as https://github.com/nextcloud/server/pull/34379/files?w=1.

@ChristophWurst ChristophWurst added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Oct 11, 2022
@PVince81
Copy link
Member

@ChristophWurst please fix for php-cs

The session token renewal does
1) Read the old token
2) Write a new token
3) Delete the old token

If two processes succeed to read the old token there can be two new tokens because
the queries were not run in a transaction. This is particularly problematic on
clustered DBs where 1) would go to a read node and 2) and 3) go to a write node.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst ChristophWurst force-pushed the fix/transactional-session-token-renewal branch from c721b4e to c5922e6 Compare October 18, 2022 06:28
@AndyScherzinger
Copy link
Member

@ChristophWurst @PVince81 how far back would we want to backport this? Asking since this might help with some large scale installations but might also hurt some in cases were long(er) running transactions might cause issues with raising the probability of deadlocks in a cluster setup.

@ChristophWurst ChristophWurst merged commit c671466 into master Oct 18, 2022
@ChristophWurst ChristophWurst deleted the fix/transactional-session-token-renewal branch October 18, 2022 09:19
@nickvergessen
Copy link
Member

The used API exists since 24

@ChristophWurst
Copy link
Member Author

Wrapping these related queries in a query is one of the proposed solution we received from the mariadb experts.

Write and delete will always run on the main database node. The transaction will only cause the read to happen on the same. I think this should be fine.

@AndyScherzinger
Copy link
Member

@ChristophWurst can you cover a backport to 24+ then? Thanks in advance 🙏

@ChristophWurst
Copy link
Member Author

/backport to stable25

@ChristophWurst
Copy link
Member Author

/backport to stable24

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

Labels

4. to release Ready to be released and/or waiting for tests to finish bug

Projects

Development

Successfully merging this pull request may close these issues.

7 participants