-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Version Information
Version of Akka.NET? "1.5.40"
Which Akka.NET Modules? Core Akka.Net, ConsistentHashingPool
Describe the bug
When creating routees in ConsistentHashingPool, the aforementioned routees are "spread" by utilizing MurmurHash into a sorted dictionary.
Murmurhash has a key-space of 32bits. This implies a 50% probability of hash collision with roughly 70k routes count, though it may happen with way fewer.
(In our case in happened with 17 hashring nodes)
To Reproduce
Steps to reproduce the behavior:
public class ConsistentHashingPool_BDay : TestKit
{
public class SampleActor : ReceiveActor
{
public SampleActor()
{
Receive<string>(msg => Sender.Tell(msg));
}
}
[Fact]
public async Task Test1()
{
var actor = Sys.ActorOf(Props.Create(() => new SampleActor()).WithRouter(new ConsistentHashingPool(100_000, (msg => msg.GetHashCode()))),
"sampleActor");
var req = "req";
await Assert.ThrowsAnyAsync<Exception>(async () => await actor.Ask<string>(req, TimeSpan.FromSeconds(10)));
}
}
Links to working reproductions on Github / Gitlab are very much appreciated
Expected behavior
Route pool should be successfully created
Actual behavior
from logs: [WARNING][01-26-2026 08:42:36.260Z][Thread 0019][ConsistentHashingRoutingLogic (akka://test)] Couldn't route message with consistent hash key [System.Byte[]] due to [An item with the same key has already been added. Key: [-1475268499, akka://test/user/sampleActor/$k~c]]
The above most probably has to do with the ConsistentHash:: Create that utilizes a SortedDictionary
Hash collisions happen there and they are unhandled (as SortedDictionary :: Add throws on duplicate key)
Environment
Are you running on Linux? Windows? Docker? Which version of .NET?
Windows 11 locally, Linux in prod. net80
Additional context
calculation are done via https://www.bdayprob.com/