[erlang-bugs] Strange behaviors in supervisor module.
Zichen Cao
zichen@REDACTED
Thu Jun 16 19:45:38 CEST 2011
Hi,
I was testing supervisor module, and I found three strange behaviors in it.
start() ->
Pid = spawn_link(fun child/0),
{ok, Pid}.
child() ->
receive
exit -> exit(normal)
end.
init(_) ->
{ok, {{one_for_one, 30000, 10000},[]}}.
f_sup1()->
{ok, Sup} = supervisor:start_link(?MODULE, []),
{ok, Child} = supervisor:start_child(Sup, {child, {supervisor,start_link, [?MODULE,[]]},
temporary,infinity,supervisor,[?MODULE]}),
exit(Child, kill),
supervisor:delete_child(Sup, child).
f_sup2()->
{ok, Sup} = supervisor:start_link(?MODULE, []),
{ok, Child1} = supervisor:start_child(Sup, {child1, {?MODULE,start,[]}, temporary,1,worker, [?MODULE]}),
{ok, Child2} = supervisor:start_child(Sup, {child2, {?MODULE,start,[]}, transient,1,worker, [?MODULE]}),
Child1 ! exit,
Child2 ! exit,
timer:sleep(100),
{supervisor:restart_child(Sup, child1),
supervisor:restart_child(Sup, child2)}.
f_sup3()->
{ok, Sup} = supervisor:start_link(?MODULE, []),
{ok, Child} = supervisor:start_child(Sup, {child, {?MODULE,start,[]}, transient,10000,worker, [?MODULE]}),
exit(Child, shutdown),
timer:sleep(100),
{Child, supervisor:which_children(Sup)}.
In f_sup1, after killing the child process, I try to delete it by calling supervisor:delete_child, it returns {error,running}.
In f_sup2, if a child processes exits with reason normal, a temporary child process cannot be restarted, but transient process can. So f_sup2 returns{{error,not_found},{ok,<0.364.0>}}. This seems inconsistent because a transient process that exits with reason normal is not supposed to be restarted.
In f_sup3, if a transient child process exits with the reason shutdown, it won't be restarted. It seems strange, since, a transient child process should be restarted unless it is terminated with the reason normal.
Zichen Cao
More information about the erlang-bugs
mailing list