Skip to content

Conversation

@sanych-sun
Copy link
Member

No description provided.

@sanych-sun sanych-sun requested a review from a team as a code owner June 17, 2025 19:05
@sanych-sun sanych-sun requested review from adelinowona and papafe and removed request for a team and papafe June 17, 2025 19:05
}

return Timeout - Stopwatch.Elapsed;
var result = Timeout - Stopwatch.Elapsed;
Copy link
Member Author

@sanych-sun sanych-sun Jun 17, 2025

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.

if (exceptions.Any())
{
throw exceptions.First();
throw new AggregateException(exceptions);
Copy link
Member Author

@sanych-sun sanych-sun Jun 17, 2025

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.

@sanych-sun sanych-sun added the bug Fixes issues or unintended behavior. label Jun 17, 2025
@sanych-sun sanych-sun changed the title CSHARP-5618: Race condition in ExclusiveConnectionPool could lead to ArgumentOutOfRangeException CSHARP-5618: CSOT: Race condition in ExclusiveConnectionPool could lead to ArgumentOutOfRangeException Jun 17, 2025

if (timeout == TimeSpan.Zero)
{
throw new TimeoutException();
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

@sanych-sun sanych-sun requested a review from BorisDog June 17, 2025 21:16
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sanych-sun sanych-sun merged commit 73c8d10 into mongodb:main Jun 18, 2025
30 of 35 checks passed
@sanych-sun sanych-sun deleted the csharp5618 branch June 18, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants