Skip to content

CSHARP-5688: Bump maxWireVersion for MongoDB 8.3 #1746

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

Merged
merged 1 commit into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/MongoDB.Driver/Core/Misc/WireVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ internal static class WireVersion
/// Wire version 27.
/// </summary>
public const int Server82 = 27;
/// <summary>
/// Wire version 28.
/// </summary>
public const int Server83 = 28;

// note: keep WireVersion.cs and ServerVersion.cs in sync

Expand Down Expand Up @@ -167,9 +171,10 @@ internal static class WireVersion
new WireVersionInfo(wireVersion: 25, major: 8, minor: 0),
new WireVersionInfo(wireVersion: 26, major: 8, minor: 1),
new WireVersionInfo(wireVersion: 27, major: 8, minor: 2),
new WireVersionInfo(wireVersion: 28, major: 8, minor: 3)
};

private static Range<int> __supportedWireVersionRange = CreateSupportedWireVersionRange(minWireVersion: Server42, maxWireVersion: Server82);
private static Range<int> __supportedWireVersionRange = CreateSupportedWireVersionRange(minWireVersion: Server42, maxWireVersion: Server83);

private static Range<int> CreateSupportedWireVersionRange(int minWireVersion, int maxWireVersion)
{
Expand Down
11 changes: 9 additions & 2 deletions src/MongoDB.Driver/ServerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ public enum ServerVersion
/// <summary>
/// Server version 8.2.
/// </summary>
Server82
Server82,

/// <summary>
/// Server version 8.3.
/// </summary>
Server83

// note: keep Server.cs and WireVersion.cs in sync as well as the extension methods below
}
Expand Down Expand Up @@ -189,7 +194,8 @@ public static ServerVersion ToServerVersion(this int wireVersion)
WireVersion.Server80 => ServerVersion.Server80,
WireVersion.Server81 => ServerVersion.Server81,
WireVersion.Server82 => ServerVersion.Server82,
_ => throw new ArgumentException($"Invalid write version: {wireVersion}.", nameof(wireVersion))
WireVersion.Server83 => ServerVersion.Server83,
_ => throw new ArgumentException($"Invalid wire version: {wireVersion}.", nameof(wireVersion))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need something like a MongoConnectionException and a better error message telling the user what to do, something like:

This version of the driver is not compatible with the version of the server.

We could add "Either use a newer version of the driver or an older version of the server" but I think the problem could happen at the other end also, so that might not be accurate... it could be "either use an older version of the driver or a newer version of the server".

We can probably tell which error message to add based on whether the unknown wire version is too large or too small.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed on Slack it turns out this exception is NOT being thrown from the connection code, so my comments above are not actually relevant.

};
}

Expand Down Expand Up @@ -224,6 +230,7 @@ public static int ToWireVersion(this ServerVersion? serverVersion)
ServerVersion.Server80 => WireVersion.Server80,
ServerVersion.Server81 => WireVersion.Server81,
ServerVersion.Server82 => WireVersion.Server82,
ServerVersion.Server83 => WireVersion.Server83,
_ => throw new ArgumentException($"Invalid server version: {serverVersion}.", nameof(serverVersion))
};
}
Expand Down
6 changes: 3 additions & 3 deletions tests/MongoDB.Driver.Tests/Core/Clusters/ClusterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void SupportedWireVersionRange_should_return_expected_result()
{
var result = Cluster.SupportedWireVersionRange;

result.Should().Be(new Range<int>(8, 27));
result.Should().Be(new Range<int>(8, 28));
}

[Fact]
Expand Down Expand Up @@ -283,8 +283,8 @@ await Record.ExceptionAsync(() => subject.SelectServerAsync(OperationContext.NoT
[Theory]
[InlineData(0, 0, false)]
[InlineData(0, 0, true)]
[InlineData(28, 29, false)]
[InlineData(28, 29, true)]
[InlineData(29, 30, false)]
[InlineData(29, 30, true)]
public async Task SelectServer_should_throw_if_any_servers_are_incompatible(int min, int max, bool async)
{
var subject = CreateSubject();
Expand Down
5 changes: 3 additions & 2 deletions tests/MongoDB.Driver.Tests/Core/Misc/WireVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void GetServerVersionForErrorMessage_should_return_expected_serverVersion
[Fact]
public void SupportedWireRange_should_be_correct()
{
WireVersion.SupportedWireVersionRange.Should().Be(new Range<int>(8, 27));
WireVersion.SupportedWireVersionRange.Should().Be(new Range<int>(8, 28));
}

[Fact]
Expand All @@ -60,7 +60,8 @@ public void ToServerVersion_should_throw_if_wireVersion_less_than_0()

[Theory]
[InlineData(99, null, null)]
[InlineData(28, null, null)]
[InlineData(29, null, null)]
[InlineData(28, 8, 3)]
[InlineData(27, 8, 2)]
[InlineData(26, 8, 1)]
[InlineData(25, 8, 0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ public void Equals_should_return_true_when_all_fields_are_equal()
[InlineData(new[] { 7, 8 }, true)]
[InlineData(new[] { 8, 8 }, true)]
[InlineData(new[] { 8, 21 }, true)]
[InlineData(new[] { 27, 27 }, true)]
[InlineData(new[] { 27, 28 }, true)]
[InlineData(new[] { 28, 28 }, false)]
[InlineData(new[] { 28, 29 }, false)]
[InlineData(new[] { 28, 28 }, true)]
[InlineData(new[] { 28, 29 }, true)]
[InlineData(new[] { 29, 29 }, false)]
[InlineData(new[] { 29, 30 }, false)]
public void IsCompatibleWithDriver_should_return_expected_result(int[] minMaxWireVersions, bool expectedResult)
{
var clusterId = new ClusterId(1);
Expand Down
Loading