Skip to content

Commit d9b9fba

Browse files
committed
Avoid rounding issues when checking Timeout values (#1700)
AsTimeout is called from the SshCommand constructor with Timeout.InfiniteTimeSpan. In this scenario the range check should never fail, but unfortunately it does in certain scenarios, due to a runtime or compiler bug (as soon as optimizations are turned off the issue miraculously disappears). Closes #1700
1 parent ebdcb3e commit d9b9fba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Renci.SshNet/Common/TimeSpanExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal static class TimeSpanExtensions
1919
/// </exception>
2020
public static int AsTimeout(this TimeSpan timeSpan, [CallerArgumentExpression(nameof(timeSpan))] string? paramName = null)
2121
{
22-
var timeoutInMilliseconds = timeSpan.TotalMilliseconds;
22+
var timeoutInMilliseconds = Math.Round(timeSpan.TotalMilliseconds);
2323
return timeoutInMilliseconds is < -1d or > int.MaxValue
2424
? throw new ArgumentOutOfRangeException(paramName, "The timeout must represent a value between -1 and Int32.MaxValue milliseconds, inclusive.")
2525
: (int)timeoutInMilliseconds;

0 commit comments

Comments
 (0)