Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ArgumentOutOfRangeException is also thrown when setting HttpClient.Timeout to more than 24 days #10962

Open
datvm opened this issue Feb 14, 2025 · 5 comments

Comments

@datvm
Copy link

datvm commented Feb 14, 2025

Type of issue

Missing information

Description

ArgumentOutOfRangeException
The timeout specified is less than or equal to zero and is not InfiniteTimeSpan.

From the source code, it actually throws when you put in value greater than about 24 days (int.MaxValuems) too:

private static readonly TimeSpan s_maxTimeout = TimeSpan.FromMilliseconds(int.MaxValue);
// ...
        public TimeSpan Timeout
        {
            get => _timeout;
            set
            {
                if (value != s_infiniteTimeout)
                {
                    ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, TimeSpan.Zero);
                    ArgumentOutOfRangeException.ThrowIfGreaterThan(value, s_maxTimeout);
                }
                CheckDisposedOrStarted();
                _timeout = value;
            }
        }

I encountered this issue when trying to set it to TimeSpan.MaxValue:

System.ArgumentOutOfRangeException: value ('10675199.02:48:05.4775807') must be less than or equal to '24.20:31:23.6470000'. (Parameter 'value')

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.timeout?view=net-9.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Net.Http/HttpClient.xml

Document Version Independent Id

199a48e3-16ed-9fe0-8957-f14f37a17acd

Article author

@karelz

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 14, 2025
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 14, 2025
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@vcsjones vcsjones added area-System.Net.Http and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 19, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl

@ManickaP
Copy link
Member

If you want "unlimited" timeout, you should use Timeout.InfiniteTimeSpan which is technically -1 ms.
BTW, the same documentation issue is with MaxResponseContentBufferSize as well.

We'd gladly take a contribution to the docs to fix these.

@ManickaP ManickaP added documentation and removed untriaged New issue has not been triaged by the area owner documentation labels Feb 19, 2025
@rzikm
Copy link
Member

rzikm commented Feb 19, 2025

Btw. technical limitation for this is due to https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.cancelafter?view=net-9.0

ArgumentOutOfRangeException
delay.TotalMilliseconds is less than -1 or greater than Int32.MaxValue (or UInt32.MaxValue - 1 on some versions of .NET). Note that this upper bound is more restrictive than TimeSpan.MaxValue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants