Skip to content

Nested selective receive fails when messages have the same object reference #212

@voidstarstar

Description

@voidstarstar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions