asynkron / protoactor-kotlin

Ultra-fast distributed cross-platform actor framework
http://proto.actor
Apache License 2.0
221 stars 25 forks source link

Actor can receive a user message before Started message is successfully processed #31

Closed james-cobb closed 6 years ago

james-cobb commented 6 years ago

Not sure what the intended behaviour is.

We have an actor that takes a long time to initialise, and this is carried out on receiving the Started message. If too long is taken a timeout exception can be thrown during initialisation. We would like to see restart attempts, but until the actor has returned from processing a Started message without exception, we don't want it to process any user messages.

However the actor does receive other user messages in between Started and Restarting messages. I wrote a quick test to demonstrate this:

    fun test() {
        val prop = fromFunc { msg ->
            println("Mssg Received " + msg.toString())
            when (msg) {
                is Started -> {
                    Thread.sleep(1000)
                    throw Exception()
                }
                else -> {

                }
            }
        }
        val pid = spawn(prop)
        for (i in 1..2) {
            send(pid, "Proto.Actor")
        }
        Thread.sleep(5000)
    }

Gives this:

Mssg Received actor.proto.Started@2f386338 Handling root failure for nonhost/$1 Restarting nonhost/$1 Reason java.lang.Exception Mssg Received actor.proto.Restarting@379abc62 Mssg Received actor.proto.Started@2f386338 Handling root failure for nonhost/$1 Restarting nonhost/$1 Reason java.lang.Exception Mssg Received Proto.Actor Mssg Received actor.proto.Restarting@379abc62

james-cobb commented 6 years ago

I have a proposed test+fix for this issue here https://github.com/crowdconnected/protoactor-kotlin/tree/issue-31

rogeralsing commented 6 years ago

Fixed by #33