Skip to content

Timeout.InfiniteTimeSpan not supported. #25068

Description

@TonyValenti

Include your code

Calling SetCommandTimeout with the Infinite timespan throws the error:

System.ArgumentException: Timeout must be greater than or equal to zero.

Code:

Context.Database.SetCommandTimeout(Timeout.InfiniteTimeSpan);

Include provider and version information

EF Core version: 5.x
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: Net5.0
Operating system: Windows
IDE: Visual Studio 2019 16.10.

Activity

  1. smitpatel commented on Jun 9, 2021

    @smitpatel
    Contributor

    Timeout.InfiniteTimeSpan has value of -1 millisecond. (Ref https://docs.microsoft.com/en-us/dotnet/api/system.threading.timeout.infinitetimespan?view=net-5.0)

    So exception thrown is correct. If you want to remove upper limit on timeout then call the API with null value. (Null command timeout may not mean infinite time out duration, it may default to connection level time out, someone from @dotnet/efteam can confirm)

  2. bricelam commented on Jun 9, 2021

    @bricelam
    Contributor

    -1 means infinite on Microsoft.Data.Sqlite. On most other providers you'll probably start hitting network timeouts eventually anyway.

    -1 means timeout immediately (when another connection has a lock on the object) in Microsoft.Data.Sqlite.

  3. roji commented on Jun 10, 2021

    @roji
    Member

    Note the following in the docs on DbCommand.CommandTimeout:

    An ArgumentException is generated if the assigned CommandTimeout property value is less than 0.
    Note to implementers, it is recommended that 0 means no timeout.

    However, we've chosen to add an overload in EF Core which accepts a TimeSpan (ADO.NET only has simple ints). Because of this, it does make sense to me to recognize Timeout.InfiniteTimeSpan and handle it properly.

  4. added this to the Backlog milestone on Jun 11, 2021
  5. added
    good first issue
    on Jun 11, 2021
  6. added a commit that references this issue on Jun 15, 2021
    c6243d8
  7. modified the milestones: Backlog, on Jul 11, 2021
  8. modified the milestones: , 6.0.0 on Nov 8, 2021
  9. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dbcontextcommunity-contributioncustomer-reportedgood first issue

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions