supervisor terminates on bad call to sc_server

10 views
Skip to first unread message

err

unread,
Oct 11, 2013, 10:48:45 PM10/11/13
to erlan...@googlegroups.com
Gist (same info is inline further down):
https://gist.github.com/d4cbcb6c81e9e27f38ac


I get that sc_lookup/1 is not exported by the sc_server,
but I'm not sure why this terminates the supervisor (sc_sup) process.


11> sc_server:insert(foo, bar).
ok
12> sc_server:lookup(foo).
bar
13> sc_server:insert(baz).       % sc_server:insert/1 doesn't exist!
** exception error: undefined function sc_server:insert/1
     in function  error_handler:crash/1 (error_handler.erl, line 106)
26>
=ERROR REPORT==== 11-Oct-2013::21:36:50 ===
** Generic server sc_sup terminating
** Last message in was {'EXIT',<0.104.0>,
                           {undef,
                               [{sc_server,insert,[baz],[]},
                                {error_handler,crash,1,
                                    [{file,"error_handler.erl"},{line,106}]},
                                {erl_eval,do_apply,6,
                                    [{file,"erl_eval.erl"},{line,573}]},
                                {shell,exprs,7,
                                    [{file,"shell.erl"},{line,674}]},
                                {shell,eval_exprs,7,
                                    [{file,"shell.erl"},{line,629}]},
                                {shell,eval_loop,3,
                                    [{file,"shell.erl"},{line,614}]}]}}
** When Server state == {state,
                            {local,sc_sup},
                            one_for_one,
                            [{child,<0.108.0>,sc_server,
                                 {sc_server,start_link,[]},
                                 permanent,2000,worker,
                                 [sc_server]}],
                            undefined,1000,3600,[],sc_sup,[]}
** Reason for termination ==
** {'function not exported',
       [{sc_server,insert,[baz],[]},
        {error_handler,crash,1,[{file,"error_handler.erl"},{line,106}]},
        {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,573}]},
        {shell,exprs,7,[{file,"shell.erl"},{line,674}]},
        {shell,eval_exprs,7,[{file,"shell.erl"},{line,629}]},
        {shell,eval_loop,3,[{file,"shell.erl"},{line,614}]}]}



Jordan Wilberding

unread,
Oct 12, 2013, 12:44:15 PM10/12/13
to erlan...@googlegroups.com
Very good question.

What happening here is that since you are starting it in the shell, the supervisor process is linked to the shell process. When that gen_server process crashes, that EXIT signal is propagated up to the shell which crashes the shell (then restarts it).

In order to get around this (only for educational purposes, don't actually do this for production code), you can add a function to sc_sup.erl like this:

start_shell() ->
    {ok, Pid} = supervisor:start_link(sc_sup, []),
    unlink(Pid).


--
You received this message because you are subscribed to the Google Groups "erlangcamp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erlangcamp+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages