Skip to content

Introduce scoped DatabaseFacade.UseCommandTimeout - #39403

Merged
AndriySvyryd merged 2 commits into
dotnet:mainfrom
SkyDevLab:feature/18895-use-command-timeout
Oct 28, 2026
Merged

AndriySvyryd merged 2 commits into
dotnet:mainfrom
SkyDevLab:feature/18895-use-command-timeout

Conversation

@SkyDevLab

@SkyDevLab SkyDevLab commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #18895

Description

Following the accepted API proposal, this PR introduces UseCommandTimeout overloads on DatabaseFacade (RelationalDatabaseFacadeExtensions):

public static IDisposable UseCommandTimeout(this DatabaseFacade databaseFacade, int? timeout)
public static IDisposable UseCommandTimeout(this DatabaseFacade databaseFacade, TimeSpan timeout)

Key Behaviors

  • Temporarily sets the command timeout for the lifetime of the returned IDisposable scope.
  • Restores the previous command timeout on scope disposal (including when exceptions occur).
  • Supports nested scopes.
  • Handles Timeout.InfiniteTimeSpan (mapped to 0) and validates negative timeouts consistently with SetCommandTimeout.
  • Updated public API baseline in \EFCore.Relational.baseline.json.
  • Added tests covering scoped execution, nested scopes, exception safety, and argument validation.

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.

🟡 Changes recommended

Public API documentation should clarify the supported null and infinite-timeout behaviors before approval.

1 open issue
What changed in this PR

This pull request introduces scoped command-timeout configuration for relational DatabaseFacade instances, with nested scopes and exception-safe restoration.

Changes:

  • Adds UseCommandTimeout overloads for nullable seconds and TimeSpan values.
  • Supports nested scopes, restoration, validation, and infinite-timeout handling.
  • Adds relational and SQL Server tests.
  • Updates the relational public API baseline.
File Summary
test/​EFCore.SqlServer.Tests/​Extensions/​SqlServerDatabaseFacadeExtensionsTest.cs Covers scoping, nesting, restoration, exception safety, infinite timeouts, and validation.
test/​EFCore.Relational.Tests/​Extensions/​RelationalDatabaseFacadeExtensionsTest.cs Verifies behavior for non-relational providers.
src/​EFCore.Relational/​Extensions/​RelationalDatabaseFacadeExtensions.cs Implements the scoped timeout APIs and restoration logic. Minor documentation updates should clarify null reset behavior and Timeout.InfiniteTimeSpan mapping.
src/​EFCore.Relational/​EFCore.Relational.baseline.json Records the two new public overloads.

Review effort: Lite

@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 51f5f16 into dotnet:main Oct 28, 2026
18 of 19 checks passed
@github-actions github-actions Bot added the api-review This PR or issue is introducing public API changes that need to be reviewed label Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

API review baseline changes for src/EFCore.Relational/EFCore.Relational.baseline.json

Show diff

The diff below was generated by ApiChief between the base and the PR.

  static class Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions
+ static IDisposable UseCommandTimeout(this DatabaseFacade databaseFacade, TimeSpan timeout);
+ static IDisposable UseCommandTimeout(this DatabaseFacade databaseFacade, int? timeout);

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

Labels

api-review This PR or issue is introducing public API changes that need to be reviewed community-contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

commandTimeout for some query only

3 participants