vlingo / xoom-actors

The VLINGO XOOM platform SDK for the type-safe Actor Model, delivering Reactive concurrency, high scalability, high-throughput, and resiliency using Java and other JVM languages.
https://vlingo.io
Mozilla Public License 2.0
229 stars 28 forks source link

ConcurrentModificationException in TestWorld.track #96

Closed roegerle closed 2 years ago

roegerle commented 2 years ago

version 1.9.3 java.util.ConcurrentModificationException at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1221) at io.vlingo.xoom.actors.testkit.TestWorld.track(TestWorld.java:131) at io.vlingo.xoom.actors.plugin.mailbox.testkit.TestMailbox.send(TestMailbox.java:75)

I'm working under the assumption that TestWorld and World for that matter are thread safe.

jakzal commented 2 years ago

@roegerle is it possible for you to provide a test case to reproduce this?

VaughnVernon commented 2 years ago

@roegerle is it possible for you to provide a test case to reproduce this?

@jakzal The Map is a plain HashMap but should be ConcurrentHashMap. My guess is that he's running both Scooter blocking mailbox and non-blocking mailboxes at the same time.

@roegerle In case you are doing otherwise, the TestWorld is meant only for testing. As @jakzal requested, please do provide a test that reproduces the issue.

roegerle commented 2 years ago

https://github.com/roegerle/vlingo-issue-96

Run it a few times to get the error. Last time it took four runs.

VaughnVernon commented 2 years ago

https://github.com/roegerle/vlingo-issue-96

Run it a few times to get the error. Last time it took four runs.

Thanks. I have changed the HashMap to ConcurrentHashMap, but that will ultimately not fix your issue. There are a few problems using TestWorld and TestActor the way that you are using them:

You will find a new test that reimplements yours, but has been renamed. You can see that it fails for various reasons. My latest test sees this (which is the TestWorld terminating too soon):

[ERROR] Errors:
[ERROR]   TestkitTest.testTestWorldActorUsedInParallelFails:102->lambda$testTestWorldActorUsedInParallelFails$0:104 NullPointer

Thus I have marked this test ignored. You can enable it to see the various and predictable failure points.

All above changes are available in the latest vlingo/xoom-actors:1.9.4-SNAPSHOT.

VaughnVernon commented 2 years ago

@roegerle @jakzal BTW, I did not mean that an actor must be run on a single unique thread. Any actor can be called by any number of unique threads, but by only one at a time.

roegerle commented 2 years ago

I thank you for the thourough response but I'm a little confused. I understand the actors themselves are not thread safe but is accessing them via the generated proxy thread safe? Which is what I thought I was doing.

VaughnVernon commented 2 years ago

The Mailbox type and the delivery semantics are what make actors thread safe. The proxy is used to reify method invocations on the proxy into objects of type Message and, under normal mailbox use, enqueue that message in the actor's mailbox.

However, there are two broad mailbox types under discussion in this context:

When you are using the TestWorld and a TestActor wrapper, the underlying mailbox type is the blocking TestMailbox. The purpose is to remove asynchronous delivery because the matter at hand is to test the protocol-to-state-transition correctness.

I hope that helps.

roegerle commented 2 years ago

It does. Thank you.