Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Timeout.InfiniteTimeSpan not supported. #25068

Closed
TonyValenti opened this issue Jun 9, 2021 · 3 comments · Fixed by #25085
Closed

Timeout.InfiniteTimeSpan not supported. #25068

TonyValenti opened this issue Jun 9, 2021 · 3 comments · Fixed by #25085
Labels
area-dbcontext closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Milestone

Comments

@TonyValenti
Copy link

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.

@smitpatel
Copy link
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)

@bricelam
Copy link
Contributor

bricelam commented Jun 9, 2021

-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
Copy link
Member

roji commented Jun 10, 2021

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.

@AndriySvyryd AndriySvyryd added this to the Backlog milestone Jun 11, 2021
@AndriySvyryd AndriySvyryd added good first issue This issue should be relatively straightforward to fix. type-enhancement labels Jun 11, 2021
@ajcvickers ajcvickers added community-contribution closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Jul 11, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0-preview6 Jul 11, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview6, 6.0.0 Nov 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area-dbcontext closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants