[erlang-questions] Supervisor, bridge and error messages

Robert Raschke rtrlists@REDACTED
Mon May 10 10:31:40 CEST 2010


On Sun, May 9, 2010 at 11:39 AM, Alessandro Sivieri <
alessandro.sivieri@REDACTED> wrote:

> Hi all,
>
> as a result of a previous discussion, I am now launching processes from a
> gen_server with supervisor_bridge, so I can have them under supervision.
> The following code is my bridge module:
>
> -module(my_process).
> -export([install/1, start/1, init/1, terminate/2]).
> install(F) ->
>    Key = uuid:uuid(),
>    ChildPid = proc_lib:spawn_link(fun() -> F() end),
>    Params = {Key, {?MODULE, start, [ChildPid]}, temporary, infinity,
> supervisor, [?MODULE]},
>    {ok, _BridgePid} = supervisor:start_child(main_sup, Params),
>    {Key, ChildPid}.
> start([ChildPid]) ->
>    supervisor_bridge:start_link(?MODULE, [ChildPid]).
> init([ChildPid]) ->
>    {ok, ChildPid, ChildPid}.
> terminate(_Reason, ChildPid) ->
>    exit(ChildPid, kill).
>
> I need to create the non-otp process linked to the supervisor_bridge
> externally (in install()), instead of in init(), because I need its pid for
> communicating with it, and I have found that I cannot bring any term
> outside
> the init() function; so, this process is created outside and then linked
> inside the bridge itself (which should work, I have checked the
> supervisor_bridge sources).
> But then, when calling install() (with a valid fun as argument), the
> following report is created:
>
> ** Reason for termination ==
> ** {{badmatch,
>        {error,
>            {{'EXIT',
>                 {function_clause,
>                     [{my_process,start,[<0.68.0>]},
>                      {supervisor,do_start_child,2},
>                      {supervisor,handle_start_child,2},
>                      {supervisor,handle_call,3},
>                      {gen_server,handle_msg,5},
>                      {proc_lib,init_p_do_apply,3}]}},
>             {child,undefined,'17a10803-f064-4718-ae46-4a6d3c88415c',
>                 {my_process,start,[<0.68.0>]},
>                 temporary,infinity,supervisor,
>                 [my_process]}}}},
>    [{my_process,install,1},
>     {my_peer,handle_call,3},
>     {gen_server,handle_msg,5},
>     {proc_lib,init_p_do_apply,3}]}
>
> Now, I have no idea from where the EXIT error is produced; I have added a
> print line in start(), before start_link, but it seems not to be executed;
> what am I doing wrong here?
>
>
>
Your child spec states: {?MODULE, start, [ChildPid]} as the Module,
Function, Arglist to use.

But your definition of start() expects a list to be passed in, not a simple
pid.

So, simply remove the [] brackets from your start/1 definition, I'd think.

Oh, the error function_clause means that you were trying to invoke a
function that exists, but where the arguments could not be matched to any
clause.

Robby


More information about the erlang-questions mailing list