Skip to content

Commit 51c7dc8

Browse files
author
Oleksandr Poliakov
committed
pr
1 parent eb38209 commit 51c7dc8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/MongoDB.Driver/Core/Misc/Ensure.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,11 @@ public static string IsNullOrNotEmpty(string value, string paramName)
460460
/// <returns>The value of the parameter.</returns>
461461
public static TimeSpan IsValidTimeout(TimeSpan value, string paramName)
462462
{
463-
if (value > TimeSpan.Zero || value == Timeout.InfiniteTimeSpan)
463+
if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan)
464464
{
465-
return value;
465+
throw new ArgumentOutOfRangeException($"Invalid timeout: {value}.", paramName);
466466
}
467-
468-
throw new ArgumentOutOfRangeException($"Invalid timeout: {value}.", paramName);
467+
return value;
469468
}
470469

471470
/// <summary>

src/MongoDB.Driver/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ private Type0CommandMessageSection<BsonDocument> CreateType0Section(OperationCon
380380
if (serverTimeout != Timeout.InfiniteTimeSpan)
381381
{
382382
serverTimeout -= _roundTripTime;
383+
if (serverTimeout < TimeSpan.Zero)
384+
{
385+
throw new TimeoutException();
386+
}
383387

384388
var serverTimeoutMs = MaxTimeHelper.ToMaxTimeMS(serverTimeout);
385389
AddIfNotAlreadyAdded("maxTimeMS", serverTimeoutMs);

src/MongoDB.Driver/ClientSessionExtensions.cs renamed to src/MongoDB.Driver/IClientSessionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace MongoDB.Driver;
1717

18-
internal static class ClientSessionExtensions
18+
internal static class IClientSessionExtensions
1919
{
2020
public static ReadPreference GetEffectiveReadPreference(this IClientSession session, ReadPreference defaultReadPreference)
2121
{

0 commit comments

Comments
 (0)