Skip to content

Reject negative timeouts in Microsoft.Data.Sqlite - #39657

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlite-negative-timeout
Nov 17, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlite-negative-timeout

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

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.

  • [ x] I've read the guidelines for contributing and seen the walkthrough
  • [x ] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [x ] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [ x] Code follows the same patterns and style as existing code in this repo

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.

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

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 ArgumentOutOfRangeException validation for command and connection default timeout properties.
  • Applied validation to both Default Timeout and Command Timeout connection-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 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 eb9fa6d into dotnet:main Nov 17, 2026
20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 18, 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