Repository navigation
Reject negative timeouts in Microsoft.Data.Sqlite - #39657
Merged
Merged
Conversation
SqliteCommand.CommandTimeout, SqliteConnection.DefaultTimeout and SqliteConnectionStringBuilder.DefaultTimeout (also reached through the "Default Timeout" and "Command Timeout" keywords) accepted negative values, unlike DbCommand's contract, SqliteParameter.Size and EF's own RelationalConnection.CommandTimeout. A negative timeout isn't treated as infinite: the busy-retry loops stop as soon as the elapsed time is >= timeout * 1000, which is immediately, so SQLITE_BUSY was thrown without waiting at all. Throw ArgumentOutOfRangeException for negative values.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the scoped timeout-validation change and its targeted regression coverage.
No open issues 🎉
What changed in this PR
This pull request makes Microsoft.Data.Sqlite reject negative timeout values across command, connection, and connection-string APIs, preventing busy-retry operations from terminating immediately.
Changes:
- Added
ArgumentOutOfRangeExceptionvalidation for command and connection default timeout properties. - Applied validation to both
Default TimeoutandCommand Timeoutconnection-string keywords. - Added regression tests covering direct assignments, keyword parsing, and preservation of default values.
| File | Description |
|---|---|
| test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs | Tests rejection of negative connection default timeout values and preservation of the existing default. |
| test/Microsoft.Data.Sqlite.Tests/SqliteConnectionStringBuilderTest.cs | Tests rejection of negative timeout values through direct assignment and both supported connection-string keywords. |
| test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs | Tests rejection of negative command timeout values and preservation of the existing default. |
| src/Microsoft.Data.Sqlite.Core/SqliteConnectionStringBuilder.cs | Validates non-negative default timeout values, including values supplied through connection-string aliases. |
| src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs | Rejects negative connection-level default timeout assignments. |
| src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs | Rejects negative command timeout assignments. |
Review effort: Lite
AndriySvyryd
approved these changes
Nov 17, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SqliteCommand.CommandTimeout, SqliteConnection.DefaultTimeout and SqliteConnectionStringBuilder.DefaultTimeout (also reached through the "Default Timeout" and "Command Timeout" keywords) accepted negative values, unlike DbCommand's contract, SqliteParameter.Size and EF's own RelationalConnection.CommandTimeout.
A negative timeout isn't treated as infinite: the busy-retry loops stop as soon as the elapsed time is >= timeout * 1000, which is immediately, so SQLITE_BUSY was thrown without waiting at all.
Throw ArgumentOutOfRangeException for negative values.