Skip to content

actor.start maybe needs to flush EXIT messages at process DOWN #114

@karlsson

Description

@karlsson

The actor.start function now uses the proc_lib:spawn_link function that creates a link between the parent and actor.
In the start sequence the parent will monitor the starting actor and receive any DOWN message and return an error.

The problem is if the parent is a supervisor that traps EXIT, it will receive an EXIT message because of the link as well as the error returned and may decide to restart the child, maybe ending up in a cyclic behaviour.

When receiving a DOWN message one should try to flush the EXIT similar to what is done in the erlang gen_server:start_link sequence in sync_start sequence in erlang proc_lib module.

Actions is to write a test with a parent trapping exits (and/or supervisor) and an actor exiting in the startup to verify that both DOWN and EXIT messages are sent to the parent and, if necessary, add code to flush the EXIT when DOWN is received.

Corresponding Erlang code to flush the EXIT:

%% After an unlink(Pid) an {'EXIT', Pid, _} link message
%% cannot arrive so receive after 0 will work,

flush_EXIT(Pid) ->
    unlink(Pid),
    receive {'EXIT', Pid, _} -> ok after 0 -> ok end.

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