Skip to content

Enhance DetectsLostConnections to Support AWS Aurora Credential Rotation Scenario #55331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

msaifmfz
Copy link
Contributor

@msaifmfz msaifmfz commented Apr 9, 2025

Summary

This pull request adds an additional connection error message to the DetectsLostConnections trait to better handle AWS Aurora database configurations that use AWS Secrets Manager with automatic password rotation.

Context

When Laravel is used in conjunction with Amazon Aurora and AWS Secrets Manager for managing database credentials, it's common for credentials to rotate automatically (e.g., weekly). If a long-running process (such as a queue worker or a job) is in progress during a credential rotation, any subsequent query attempts may fail with the following error:

SQLSTATE[HY000] [1045] Access denied for user 'username'@'host' (using password: YES)

This error is currently not interpreted by Laravel as a "lost connection", even though it effectively is one in this context — since the stored credentials have expired or changed mid-process.

Solution

This PR explicitly adds the following error message pattern to the DetectsLostConnections trait:

SQLSTATE[HY000] [1045] Access denied for user

This helps Laravel detect these kinds of "soft" lost connections that result from credentials rotating behind the scenes.

Why This Matters

  • Ensures Laravel can gracefully handle rotated secrets and attempt reconnects instead of failing fatally.
  • Improves DX (developer experience) when using modern cloud-native database setups.
  • Aligns with Laravel's principle of building robust and developer-friendly systems that handle real-world cloud infra cases.

Notes

  • This change is backward-compatible and only adds one more string check to the list of known lost connection errors.
  • It targets a very specific but increasingly common cloud architecture use case.

@msaifmfz msaifmfz changed the title Update DetectsLostConnections.php Enhance DetectsLostConnections to Support AWS Aurora Credential Rotation Scenario Apr 9, 2025
@taylorotwell taylorotwell merged commit 1e37ba6 into laravel:12.x Apr 9, 2025
60 checks passed
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.

2 participants