我有一棵监督树,由gen_servers组成,作为临时的孩子,它们的寿命很短。当清理和终止的时候,每个孩子都会收到一条消息。
有一个控制器过程,从这些子程序中保存Pid的小块,这是受我从丁尼项目中读到的代码的启发。
在他们的情况下,他们使用max_age设置来终止他们的通道,其中有些代码我不太明白。
在我的例子中,在做了一些清理之后,我尝试使用supervisor:terminate_child(Sup, Pid)
,如下所示:
子程序本身在控制器上执行RPC:
fs_outbound_controller:deallocate_me(UUID, self());
主计长:
deallocate_me(UUID, Pid) ->
gen_server:cast(?SERVER, {deallocate_me, UUID, Pid}).
handle_cast({deallocate_me, UUID, Pid}, #state{dict = Uuid2Pid} = State) ->
NewDict = dict:erase(UUID, Uuid2Pid),
supervisor:terminate_child(fs_outbound_extn_sup, Pid),
error_logger:info_msg("Successfully deallocated ~p", [UUID]),
{noreply, State#state{dict=NewDict}}.
我观察到的问题是,错误记录器报告有关gen_server终止返回值的崩溃?
** Reason for termination ==
** {bad_return_value,ok}
谢谢你的帮助。
编辑
我做了其他事情,将对deallocate_me的调用从RPC转移到子控制器的消息。考虑到可能对控制器执行RPC调用的子节点终止了该子进程,从而导致了一些返回问题。处理程序保持不变。
supervisor:terminate_child(fs_outbound_extn_sup,handle_info({deallocate_me,UUID,Pid},#state{dict = Uuid2Pid} = State) -> NewDict =dict:擦除(UUID,Uuid2Pid),State#state Pid),error_logger:info_msg(“成功地释放~p",UUID),{noreply,State#state{dict=NewDict}。
但现在我还是明白:
** Reason for termination ==
** {bad_return_value,{deallocate_me,"49d9f7cb-62d3-4c3f-abf1-a19848967a9a",
<0.50.0>}}
发布于 2012-11-15 18:40:22
在我看来
fs_outbound_controller:deallocate_me(UUID, self());
被调用为handle_call/3
、handle_cast/2
或handle_info/2
中的最后一条语句。正如您可能知道的那样,这些人期待的是类似于{reply, ...}
、{noreply, ...}
或{stop, ...}
的东西。
记住,gen_server:cast/2
总是返回ok
,而ServerPid ! Message
总是返回Message
本身。这就是为什么你第一次被告知{bad_return_value, ok}
,第二次被告知{bad_return_value, MessageSent}
。
在您的情况下,我将坚持使用gen_server:cast
方法,只需在错误调用之后将正确的返回值放在正确的位置:
fs_outbound_controller:deallocate_me(UUID, self()),
{noreply, State}; %% strongly depends on what your logic there is
https://stackoverflow.com/questions/13401599
复制相似问题