-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-3549: CSOT: Add timeoutMS to settings #1721
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
0942f85
to
af44109
Compare
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.
Overall looks good. See minor comments.
@@ -459,12 +460,12 @@ public static string IsNullOrNotEmpty(string value, string paramName) | |||
/// <returns>The value of the parameter.</returns> | |||
public static TimeSpan IsValidTimeout(TimeSpan value, string paramName) | |||
{ | |||
if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) | |||
if (value > TimeSpan.Zero || value == Timeout.InfiniteTimeSpan) |
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.
Why did you flip the logic in this method?
All the other methods end with return value
.
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.
Somehow this way it's easier to understand for me. But not critical, will revert to follow other methods pattern.
{ | ||
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.
Is it OK that we no longer throw an exception?
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.
Yes, you are right. We should throw for negative timeouts. Will return the exception.
|
||
namespace MongoDB.Driver | ||
internal static class ClientSessionExtensions |
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.
Should this file/class be called IClientSessionExtensions
?
@@ -87,7 +87,7 @@ public CancellationToken CombinedCancellationToken | |||
} | |||
private Stopwatch Stopwatch { get; } | |||
|
|||
public TimeSpan Timeout { get; } | |||
public TimeSpan? Timeout { get; } |
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.
I find it really unhelpful when a class has BOTH fields and auto-properties.
I'm not a fan of auto-properties in general, but I'm specially not a fan of mixing fields and auto-properties in the same class. Mixing them makes it much harder to understand what state a class maintains.
@@ -114,13 +109,13 @@ public override IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle se | |||
if (isAggregateToCollection) | |||
{ | |||
var aggregateOperation = CreateAggregateToCollectionOperation(renderedPipeline, options); | |||
ExecuteWriteOperation(session, aggregateOperation, cancellationToken); | |||
ExecuteWriteOperation(session, aggregateOperation, options.Timeout, cancellationToken); |
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.
Sometime I see options.Timeout
and other times I see options?.Timeout
.
Should they ALL have ?
?
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.
Let me double-check. I think in some cases there is no-way to have null options.
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.
Yep. There are number of cases when options is guaranteed to be not-null. In all other cases there is Null-conditional operators.
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.
That's a pain. I leave it to you then to check that there are no missing ?
.
@@ -296,7 +297,7 @@ public TimeSpan HeartbeatTimeout | |||
get { return _heartbeatTimeout; } | |||
set | |||
{ | |||
if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) | |||
if (value < TimeSpan.Zero && value != System.Threading.Timeout.InfiniteTimeSpan) |
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.
Why this change?
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.
Now as MongoUrlBuilder
has property named Timeout
, we should use full name here.
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.
That's unfortunate.
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 with minor comments
@@ -444,11 +444,12 @@ public static string IsNullOrNotEmpty(string value, string paramName) | |||
/// <returns>The value of the parameter.</returns> | |||
public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName) | |||
{ | |||
if (value != null) | |||
if (value == null) |
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.
There was probably no need to touch this file at all.
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.
I don't mind leaving these changes in. I think they improve this code a bit.
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.
Maybe not...
In general I don't like making random changes to files that have nothing to do with the PR.
If we think these methods could be written in a better way we should make a ticket for it.
The reason that all methods end with return value
is that in general an Ensure
method might throw more than one exception, so the general pattern is:
- check for invalid condition 1 and throw exception with suitable message
- check for invalid condition 2 and throw exception with suitable message
- ...
- return value
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.
Same story here as with previous change in the file: some how "quick returns" works better for me to understand the code. But I do not mind to revert the code.
And technically this method is kind of related to the PR: we used to have unused method Ensure.IsValidTimeout
. Instead of implementing new method I've decided to adopt it and was making sure the logic is appropriate for the usage. That's the reason why I touched the file.
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.
OK
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.
Anyhow: reverted 🙂
@@ -114,13 +109,13 @@ public override IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle se | |||
if (isAggregateToCollection) | |||
{ | |||
var aggregateOperation = CreateAggregateToCollectionOperation(renderedPipeline, options); | |||
ExecuteWriteOperation(session, aggregateOperation, cancellationToken); | |||
ExecuteWriteOperation(session, aggregateOperation, options.Timeout, cancellationToken); |
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.
That's a pain. I leave it to you then to check that there are no missing ?
.
@@ -296,7 +297,7 @@ public TimeSpan HeartbeatTimeout | |||
get { return _heartbeatTimeout; } | |||
set | |||
{ | |||
if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) | |||
if (value < TimeSpan.Zero && value != System.Threading.Timeout.InfiniteTimeSpan) |
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.
That's unfortunate.
throw new TimeoutException(); | ||
} | ||
serverTimeout -= _roundTripTime; | ||
if (serverTimeout < TimeSpan.Zero) |
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.
Should this be changed to <=
?
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.
+1
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.
Done, thank you!
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! left a comment you can tackle if you think it's ok to do it now.
var effectiveComment = _comment; | ||
var effectiveHint = _hint; | ||
var effectiveMax = _max; | ||
var effectiveMaxTime = _maxTime; | ||
var effectiveMin = _min; | ||
var effectiveReturnKey = _returnKey; | ||
var effectiveShowRecordId = _showRecordId; |
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.
What's the point of all this effective variables? can't we just remove them while we are here?
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.
Done.
throw new TimeoutException(); | ||
} | ||
serverTimeout -= _roundTripTime; | ||
if (serverTimeout < TimeSpan.Zero) |
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.
+1
@@ -444,11 +444,12 @@ public static string IsNullOrNotEmpty(string value, string paramName) | |||
/// <returns>The value of the parameter.</returns> | |||
public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName) | |||
{ | |||
if (value != null) | |||
if (value == null) |
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.
I don't mind leaving these changes in. I think they improve this code a bit.
@@ -444,11 +444,12 @@ public static string IsNullOrNotEmpty(string value, string paramName) | |||
/// <returns>The value of the parameter.</returns> | |||
public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName) | |||
{ | |||
if (value != null) | |||
if (value == null) |
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.
Maybe not...
In general I don't like making random changes to files that have nothing to do with the PR.
If we think these methods could be written in a better way we should make a ticket for it.
The reason that all methods end with return value
is that in general an Ensure
method might throw more than one exception, so the general pattern is:
- check for invalid condition 1 and throw exception with suitable message
- check for invalid condition 2 and throw exception with suitable message
- ...
- return value
@@ -444,11 +444,12 @@ public static string IsNullOrNotEmpty(string value, string paramName) | |||
/// <returns>The value of the parameter.</returns> | |||
public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName) | |||
{ | |||
if (value != null) | |||
if (value == null) |
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.
OK
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.