dotnet/efcore

Timeout.InfiniteTimeSpan not supported.

TonyValenti opened this issue · 3 comments

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.

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)

-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.

roji commented

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.