Unplanned
Last Updated: 17 Jun 2025 07:09 by ADMIN
Piet
Created on: 11 Jun 2025 13:40
Category: Telerik Document Processing
Type: Bug Report
0
CancelationTokenSourceFactory.CreateTokenSource(TimeSpan? timeSpan) does not do proper argument checking

Read the documentation for CancelationTokenSource.CancelAfter:

this method will throw an ArgumentOutOfRangeException when: 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.

----------------------------------------------------

your code in CancelationTokenSourceFactory.CreateTokenSource does this check:

if (timeSpan.HasValue && timeSpan.Value != TimeSpan.MaxValue)

this check for TimeSpan.MaxValue seems totally pointless here, if timeSpan is anything between ~2147483647 and 922337203685476 milliseconds long this will still just throw a ArgumentOutOfRangeException.

I suspect that this check was intended as a way to prevent creating a cancellation timer that never triggers in the CancellationTokenSource, which should look like this:

if (timeSpan.HasValue && timeSpan != Timeout.InfiniteTimeSpan) //Timeout.InfiniteTimeSpan is -1 milliseconds
which still seems like premature optimization with no noticeable benefit but at least it isn't completely pointless.
2 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 17 Jun 2025 07:09

Hi, Piet,

I am sorry to hear that you are facing any difficulties with the timeout mechanism offered by Telerik Document Processing.

Indeed, the referred feedback item is related to the TimeSpan.MaxValue handling. The TimeSpan interval is up to the developer and should be considered with the environment-specific configurations. In case of developing a web application for example, set such a timeout interval value that would be safe enough to protect the application from potential DDoS attacks. If the application is expected to be delivered directly to the end-users, it is possible to use TimeSpan=null as well.

Since the CancellationTokenSource class offers two overloads for the CancelAfter method, CancelAfter(Int32) and CancelAfter(TimeSpan), we are expected to handle any exceptions if a valid interval is passed as an argument.

According to the MSDN information, ArgumentOutOfRangeException is thrown when: 

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.

I have approved this bug report. I have also updated your Telerik points for bringing this to our attention. We will do our best to address it properly. Make sure that you click the Follow button to get notified for any status changes.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Piet
Posted on: 11 Jun 2025 13:50

this check was probably added in reponse this this bug ticket: https://feedback.telerik.com/document-processing/1680730-spreadprocessing-argumentoutofrangeexception-specified-argument-was-out-of-the-range-of-valid-values-parameter-delay-when-using-timeout-with-timespan-maxvalue

but this is not a good solution at all, plus it only 'solves' the thrown exception for a single case out of literal trillions, and does so by simply ignoring the given TimeSpan.

If an invalid timeout is provided, the method should throw an ArgumentOutOfRangeException. If users do not want a timeout, they should pass either a null or Timeout.InfiniteTimespan, not TimeSpan.MaxValue.

now there is just this weird situation where passing TimeSpan.MaxValue does nothing even though is this different from normal C# timeout cancellation behaviour and therefore unexpected and not intuitive.