Skip to content

Commit 71f0350

Browse files
AppVersion.CompareTo missing else if breaks comparison symmetry (#8051)
The second condition in the rest-string comparison was an 'if' instead of 'else if', causing the first branch's result (diff = 1) to be immediately overwritten by the else branch. This made release versions appear less than their pre-release counterparts (e.g. '1.2.0' < '1.2.0-M1'), violating IComparable<T> symmetry. This could cause non-deterministic shard allocation ordering during rolling updates from pre-release to release versions via AbstractLeastShardAllocationStrategy. Added regression test for the reverse comparison direction. Co-authored-by: Aaron Stannard <aaron@petabridge.com>
1 parent 2226305 commit 71f0350

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/core/Akka.Tests/Util/AkkaVersionSpec.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ public void Version_should_compare_extra()
6666
AppVersion.Create("1.2.0-M1").Should().Be(AppVersion.Create("1.2-M1"));
6767
AppVersion.Create("1.2.3-M1").Should().NotBe(AppVersion.Create("1.2.3-M2"));
6868
AppVersion.Create("1.2-M1").Should().BeLessThan(AppVersion.Create("1.2.0"));
69-
AppVersion.Create("1.2.0-M1").Should().BeLessThan(AppVersion.Create("1.2.0"));
7069
AppVersion.Create("1.2.3-M2").Should().BeGreaterThan(AppVersion.Create("1.2.3-M1"));
70+
71+
// ensure comparisons are symmetrical
72+
AppVersion.Create("1.2.0-M1").Should().BeLessThan(AppVersion.Create("1.2.0"));
73+
AppVersion.Create("1.2.0").Should().BeGreaterThan(AppVersion.Create("1.2.0-M1"));
7174
}
7275

7376
[Fact]

src/core/Akka/Util/AppVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public int CompareTo(AppVersion other)
229229
{
230230
if (_rest == "" && other._rest != "")
231231
diff = 1;
232-
if (other._rest == "" && _rest != "")
232+
else if (other._rest == "" && _rest != "")
233233
diff = -1;
234234
else
235235
diff = string.Compare(_rest, other._rest, StringComparison.Ordinal);

0 commit comments

Comments
 (0)