Skip to content

feat: add per-query command timeout - #39278

Closed
GeorgiPopovIT wants to merge 1 commit into
dotnet:mainfrom
GeorgiPopovIT:feature/scoped-command-timeout
Closed

GeorgiPopovIT wants to merge 1 commit into
dotnet:mainfrom
GeorgiPopovIT:feature/scoped-command-timeout

Conversation

@GeorgiPopovIT

Copy link
Copy Markdown

Added scoped command timeout to DatabaseFacade.

Summary of the changes:

  • Added WithCommandTimeout(int? timeout) extension method to temporarily set the command timeout in seconds.
  • Added WithCommandTimeout(TimeSpan timeout) overload to specify the timeout using a TimeSpan.
  • Restored the previous timeout on disposal by returning an IDisposable scope, supporting the using pattern.
  • Introduced CommandTimeoutScope to store the original timeout and restore it when disposed; repeated disposal is safe.
  • Added XML documentation and an example demonstrating scoped timeout usage.
  • Added automated tests covering synchronous and asynchronous queries, injected and non-injected DbContext instances, both overloads, and timeout restoration.
  • Updated the relational API baseline to include the two new public extension methods.

Related to #18895

If it's helpful, I will be happy.

Allow specifying a command timeout for individual queries.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 14:48
@GeorgiPopovIT
GeorgiPopovIT requested a review from a team as a code owner October 16, 2026 14:48

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.

🔵 Needs a closer look

The new public API warrants maintainer design review, and provider-runtime validation remains unexecuted.

0 open findings

What changed in this PR

Adds scoped command timeouts to EF Core’s relational DatabaseFacade, allowing temporary overrides that restore the previous timeout on disposal.

Changes:

  • Adds integer and TimeSpan overloads with usage documentation.
  • Introduces a disposable scope with safe repeated disposal.
  • Adds synchronous/asynchronous coverage and updates the public API baseline.
File Description
test/​EFCore.Relational.Specification.Tests/​CommandInterceptionTestBase.cs Tests scoped timeouts, nesting, and restoration.
src/​EFCore.Relational/​Storage/​Internal/​CommandTimeoutScope.cs Restores the previous timeout on disposal.
src/​EFCore.Relational/​Extensions/​RelationalDatabaseFacadeExtensions.cs Adds documented scoped-timeout overloads.
src/​EFCore.Relational/​EFCore.Relational.baseline.json Records the two new public methods.

🧠 Review effort: Balanced


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

@AndriySvyryd AndriySvyryd self-assigned this Oct 21, 2026
@AndriySvyryd

Copy link
Copy Markdown
Member

Superseded by #39403

@AndriySvyryd AndriySvyryd removed their assignment Oct 26, 2026
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.

3 participants