-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5618: CSOT: Race condition in ExclusiveConnectionPool could lead to ArgumentOutOfRangeException #1712
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,13 @@ public TimeSpan RemainingTimeout | |
| return System.Threading.Timeout.InfiniteTimeSpan; | ||
| } | ||
|
|
||
| return Timeout - Stopwatch.Elapsed; | ||
| var result = Timeout - Stopwatch.Elapsed; | ||
| if (result < TimeSpan.Zero) | ||
| { | ||
| result = TimeSpan.Zero; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -69,7 +75,7 @@ public bool IsTimedOut() | |
| return false; | ||
| } | ||
|
|
||
| return remainingTimeout < TimeSpan.Zero; | ||
| return remainingTimeout == TimeSpan.Zero; | ||
| } | ||
|
|
||
| public void ThrowIfTimedOutOrCanceled() | ||
|
|
@@ -141,6 +147,11 @@ public async Task WaitTaskAsync(Task task) | |
|
|
||
| public OperationContext WithTimeout(TimeSpan timeout) | ||
| { | ||
| if (timeout != System.Threading.Timeout.InfiniteTimeSpan && timeout < TimeSpan.Zero) | ||
| { | ||
| throw new ArgumentOutOfRangeException(nameof(timeout), timeout, "The timeout must represent a value between -1 and Int32.MaxValue, inclusive."); | ||
| } | ||
|
|
||
| var remainingTimeout = RemainingTimeout; | ||
| if (timeout == System.Threading.Timeout.InfiniteTimeSpan) | ||
| { | ||
|
|
@@ -151,6 +162,11 @@ public OperationContext WithTimeout(TimeSpan timeout) | |
| timeout = remainingTimeout; | ||
| } | ||
|
|
||
| if (timeout == TimeSpan.Zero) | ||
| { | ||
| throw new TimeoutException(); | ||
|
||
| } | ||
|
|
||
| return new OperationContext(timeout, CancellationToken) | ||
| { | ||
| ParentContext = this | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ public static void ExecuteOnNewThreads(int threadsCount, Action<int> action, int | |
|
|
||
| if (exceptions.Any()) | ||
| { | ||
| throw exceptions.First(); | ||
| throw new AggregateException(exceptions); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throwing like it was before messes up the call stack, when |
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many .net APIs that accepts timeouts validates the timeout and throws
ArgumentExceptionon negative values (for example SemaphoreSlim). On other hand if it'sTimeSpan.Zeroit just considered as timeout out. So it's safer to useTimeSpan.Zerofor timed out contexts.