Skip to content

Restrict SQL Server login failure retries to post-creation checks - #38927

Merged
AndriySvyryd merged 3 commits into
dotnet:mainfrom
saifahmed34:issue-38886-retry-login-failure
Sep 10, 2026
Merged

AndriySvyryd merged 3 commits into
dotnet:mainfrom
saifahmed34:issue-38886-retry-login-failure

Conversation

@saifahmed34

@saifahmed34 saifahmed34 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #38886

SQL error 18456 is transient immediately after Azure SQL database creation,
but it should not be retried during ordinary CanConnectAsync() or migration
existence checks.

This change restricts 18456 retries to the post-creation existence check and
adds synchronous and asynchronous regression tests.

@saifahmed34
saifahmed34 requested a review from a team as a code owner September 6, 2026 08:44
@saifahmed34
saifahmed34 marked this pull request as draft September 6, 2026 09:17
@saifahmed34
saifahmed34 marked this pull request as ready for review September 6, 2026 09:17
@saifahmed34 saifahmed34 closed this Sep 6, 2026
@saifahmed34
saifahmed34 deleted the issue-38886-retry-login-failure branch September 6, 2026 10:29
@saifahmed34
saifahmed34 restored the issue-38886-retry-login-failure branch September 6, 2026 10:34
@saifahmed34 saifahmed34 reopened this Sep 6, 2026
@saifahmed34

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@AndriySvyryd AndriySvyryd self-assigned this Sep 6, 2026
@AndriySvyryd AndriySvyryd added this to the 12.0.0 milestone Sep 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The functional change is narrowly scoped and covered by targeted sync/async regression tests, with only a minor documentation clarification suggested.

Pull request overview

This PR fixes an EF Core SQL Server hang scenario where login failures (SQL error 18456) were being treated as retryable during normal existence/connectivity checks (e.g., CanConnectAsync and migration-related existence checks), by limiting 18456 retries to the post-database-creation existence check path.

Changes:

  • Updated SqlServerDatabaseCreator.Exists/ExistsAsync retry logic to only treat 18456 as retryable when running the post-creation “retry-on-not-exists” flow.
  • Added unit regression coverage to ensure create-time existence checks still retry on 18456, while ordinary Exists/ExistsAsync do not retry and instead throw.
File summaries
File Description
src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs Gate 18456 retry behavior behind the post-creation existence-check flag.
test/EFCore.SqlServer.Tests/Storage/Internal/SqlServerDatabaseCreatorTest.cs Add sync/async regression tests for create-time retry vs. ordinary exists-time no-retry on 18456.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@AndriySvyryd AndriySvyryd 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.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit bfecd6a into dotnet:main Sep 10, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database.CanConnectAsync() / Database.MigrateAsync() retries on authentication failure instead of throwing (SQL Server)

3 participants