[erlang-questions] How to get the start parameter when a gen_fsm exits abnormally?

raocheng <>
Fri Oct 12 08:37:37 CEST 2012


I have created a gen_fsm(module: test_service), which is started as a
temporary child of supervisor(module: test_service_sup).
Since the instance of test_service can be created dynamically, I use the
simple_one_for_one strategy.

However, when the FSM(test_service) exit abnormally, we can not get the
start parameters for the FSM in SUPERVISOR REPORT:
2012-10-12 14:15:28 =SUPERVISOR REPORT====
     Supervisor: {local,test_service_sup}
     Context:    child_terminated
     Reason:     timeout
     Offender:
[{pid,<0.2250.0>},{name,test_service},{mfargs,{test_service,start_link,undefined}},{restart_type,temporary},{shutdown,infinity},{child_type,worker}]

So it's hard for us to figure out which test_service instance has failed.
 Is there any better method ?

Thanks in advance!

FYI:
1. If test_service is registered as a  permanent instead of temporary child
of test_service_sup, then when it exits abnormally, the UPERVISOR REPORT
will include its start parameters.

2. This is the code:
1)
-module(test_service).
-behaviour(gen_fsm).

start_link(Parameter) ->
gen_fsm:start_link(?MODULE, [Parameter], []).

init([Parameter]) ->
  ...
  {ok, trying, state}.

2)
-module(test_service_sup).
start_child(Parameter) ->
supervisor:start_child(?SERVER, [Parameter]).

init([]) ->
TestServiceSpec = {test_service,
        {test_service, start_link, []},
        temporary,
        infinity,
        worker,
        [test_service]},
    {ok, { {simple_one_for_one, 0, 1}, [TestServiceSpec]} }.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121012/dc4cd981/attachment.html>


More information about the erlang-questions mailing list