asynkron / protoactor-go

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
http://proto.actor
Apache License 2.0
5.03k stars 522 forks source link

Remoting: Forward message to Parent not working #257

Closed chriskolenko closed 5 years ago

chriskolenko commented 5 years ago

I'm having an issue sending messages to self or the actors parent when receiving a message from a remote actor.

I've build a proxy actor to send messages

type MessageBuilder func() (proto.Message, error)

type Proxy struct {
    to      *actor.PID
    builder MessageBuilder
}

func (a *Proxy) Receive(ctx actor.Context) {
    switch ctx.Message().(type) {
    case *actor.Started:
        a.Started(ctx)
    default:
        ctx.Forward(ctx.Parent())
    }
}

func (a *Proxy) Started(ctx actor.Context) {
    // build the message.
    msg, err := a.builder()
    if err != nil {
        return
    }

    // send it!.
    ctx.Request(a.to, msg)
}

When receiving the message back from a remote actor ctx.Forward executes but the message never gets to the parent.

chriskolenko commented 5 years ago

Here is the mailbox stats:

Problem is at the bottom. You can see the post in the parent.. but it never gets to the actor.

Message posted: eeb3ad27-251a-4f16-abd8-23bff606806d *actor.MessageEnvelope
Message received: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.MessageEnvelope

LOG:

Mailbox started: eeb3ad27-251a-4f16-abd8-23bff606806d
Message posted: eeb3ad27-251a-4f16-abd8-23bff606806d *actor.Started
2018-10-20T15:33:04.400+1100    INFO    actorutils/props.go:23  Message received        {"self": "127.0.0.1:6030/twitch-bot", "sender": "nil", "message_type": "*actor.Started", "message": {}}
What.... TwitchBot
Mailbox started: db2d29d8-1ac8-48d4-b981-b8532873ddaf
Message posted: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.Started
Message posted: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.Watch
2018-10-20T15:33:12.013+1100    INFO    actorutils/props.go:23  Message received        {"self": "127.0.0.1:6030/twitch-bot/join$2", "sender": "nil", "message_type": "*actor.Started", "message": {
}}
Message received: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.Started
Message received: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.Watch
No more messages: db2d29d8-1ac8-48d4-b981-b8532873ddaf
2018/10/20 04:33:12 [REMOTE] Started EndpointWatcher address="127.0.0.1:6000"
2018/10/20 04:33:12 [REMOTE] Started EndpointWriter address="127.0.0.1:6000"
2018/10/20 04:33:12 [REMOTE] EndpointWriter connecting address="127.0.0.1:6000"
2018/10/20 04:33:12 [REMOTE] EndpointWriter connected address="127.0.0.1:6000"
Message posted: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.MessageEnvelope
2018-10-20T15:33:12.055+1100    INFO    actorutils/props.go:23  Message received        {"self": "127.0.0.1:6030/twitch-bot/join$2", "sender": "nil", "message_type": "*messages.NotModified", "mess
age": ""}
Message posted: eeb3ad27-251a-4f16-abd8-23bff606806d *actor.MessageEnvelope
Message received: db2d29d8-1ac8-48d4-b981-b8532873ddaf *actor.MessageEnvelope
No more messages: db2d29d8-1ac8-48d4-b981-b8532873ddaf
chriskolenko commented 5 years ago

Bahahah.. I had a blocking call in my actor. Meaning the actor never stopped processing the message.