-
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
Conversation
…ArgumentOutOfRangeException
@@ -53,7 +53,13 @@ public TimeSpan RemainingTimeout | |||
return System.Threading.Timeout.InfiniteTimeSpan; | |||
} | |||
|
|||
return Timeout - Stopwatch.Elapsed; | |||
var result = Timeout - Stopwatch.Elapsed; |
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 ArgumentException
on negative values (for example SemaphoreSlim). On other hand if it's TimeSpan.Zero
it just considered as timeout out. So it's safer to use TimeSpan.Zero
for timed out contexts.
@@ -29,7 +29,7 @@ public static void ExecuteOnNewThreads(int threadsCount, Action<int> action, int | |||
|
|||
if (exceptions.Any()) | |||
{ | |||
throw exceptions.First(); | |||
throw new AggregateException(exceptions); |
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.
throwing like it was before messes up the call stack, when AggregateException
can preserve the original stack trace of InnerException.
@@ -151,6 +162,11 @@ public OperationContext WithTimeout(TimeSpan timeout) | |||
timeout = remainingTimeout; | |||
} | |||
|
|||
if (timeout == TimeSpan.Zero) | |||
{ | |||
throw new TimeoutException(); |
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.
Are you sure about throwing here, can't we create timed out contexts?? Feels like throwing should be part of some explicit validation like ThrowIfTimedOutOrCanceled
.
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.
Honestly not sure. Probably you are right, as throwing here might be not-expected, but throwing once we decide to Wait on something - will be more expected behavior.
Will revert.
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.
Reverted.
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.
LGTM
No description provided.