- Notifications
You must be signed in to change notification settings - Fork 568
Description
This bug occurs when sending messages a and b to an actor such that a == b is true. This only appears to affect selective receive calls that are nested.
A very simple example to consistently reproduce the bug:
ActorRef<Integer> actorRef = new BasicActor<Integer, Integer>() { @Override protected Integer doRun() throws InterruptedException, SuspendExecution { Integer result = receive(a -> a + receive(b -> b)); System.out.println(result); return null; } }.spawn(); // Both messages share the same reference actorRef.send(1); actorRef.send(1);Expected result: Print 2.
Actual result: It looks like one of the messages is silently dropped.
When changing the numbers to two different numbers, the bug goes away.
I suspect the bug might be caused by this section, but I am not really sure.
I think it's very important to allow the same message to be sent multiple times, especially since it is considered good practice to make messages immutable. I happened to run into this bug with my own custom message class, but any class that uses the flyweight pattern or interning for efficiency would also be affected (including enums, Integer, String, etc.).
Since this bug can occur due to a race condition, it is possible that this may also be the cause of other issues related to dropped messages.