Skip to content

sys_recv not called on Actor #173

Description

@milgner

Scenario: my actor registers a schedule and I was under the impression that I should cancel the schedule when the actor is shutting down. Unfortunately, Actor::post_stop doesn't have a reference to ActorSystem so I cannot cancel the schedule there.

It's possible that schedules for terminated actors get cleaned up automatically but during experimentation I realised that Actor::sys_recv doesn't get invoked even though the documentation suggests that it would be.

The following code only prints "Stopping the actor..." but not "System message!".

impl Actor for MyActor {
    type Msg = MyActorMsg;

    fn post_stop(&mut self) {
        println!("Stopping the actor for {}", self.configuration.uri);
        match self.schedule_id {
            Some(schedule_id) => {
                // TODO: how to cancel the schedule w/o reference to the ActorSystem?
                // ctx.system.cancel_schedule(schedule_id);
            }
            None => {
                warn!("Stopping the actor without any schedule running");
            }
        }
    }

    fn sys_recv(&mut self, ctx: &Context<Self::Msg>, msg: SystemMsg, sender: Sender) {
        println!("System message!");
    }

    fn recv(&mut self, ctx: &Context<Self::Msg>, msg: Self::Msg, sender: Sender) {
        self.receive(ctx, msg, sender)
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions