[4.x]: CP login issues when using replica database
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
What happened?
Description
We configured a read replica database, but this causes login issues when there's some lag in syncing with the master db.
At these moments we are unable to login. We don't get a clear error and we are just redirected back to the login page.
In our logs we see the following warning:
web yii\web\User::renewAuthStatus [WARNING] Invalid session auth key attempted for user
Which I can resolve to this line:
https://github.com/craftcms/cms/blob/4.x/src/elements/User.php#L1049
Looks like the record isn't in the replica yet due to the lag. When we disable the replica, it all works fine.
Maybe this query should always be executed on the master db?
Craft CMS version
4.8.5
PHP version
8.2.13
Operating system and version
No response
Database type and version
MySQL 8.0.36 (AWS RDS)
Image driver and version
No response
Installed plugins and versions
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/elements/User.php:1049 and trace the auth-key lookup when a read replica is configured. Reproduce the login failure with replica lag, then verify that authentication still reads the required record from the master database and that the user is no longer redirected to the login page.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- authentication, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100