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

15 views
Skip to first unread message

raocheng

unread,
Oct 12, 2012, 2:37:37 AM10/12/12
to erlang-q...@erlang.org
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]} }.
Reply all
Reply to author
Forward
0 new messages