2

一時的な子としてgen_serversで構成される監視ツリーがあり、寿命は短いです。クリーンアップして終了する時間になると、各子はメッセージを受け取ります。

私がtinymqプロジェクトから読んだコードに触発されて、これらの子供たちからの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}}.

私が観察する問題は、ERRORロガーがgen_server終了の戻り値に関してクラッシュを報告することです。

** Reason for termination == 
** {bad_return_value,ok}

あなたの助けに感謝します。

編集

私は別のことをしました。deallocate_meへの呼び出しをRPCから子からコントローラーへのメッセージに移動しました。おそらく子供がコントローラーにRPC呼び出しを行っていて、その子供が終了したのではないかと考えて、いくつかのリターンの問題を引き起こしていました。ハンドラーは同じままです

handle_info({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( "正常に割り当て解除されました〜 p "、[UUID])、{noreply、State#state {dict=NewDict}}。

しかし、今でも私は次のようになります。

** Reason for termination == 
** {bad_return_value,{deallocate_me,"49d9f7cb-62d3-4c3f-abf1-a19848967a9a",
                                    <0.50.0>}}
4

1 に答える 1

1

私にはそう思われます

fs_outbound_controller:deallocate_me(UUID, self());

handle_call/3、、handle_cast/2またはのいずれかの内部の最後のステートメントとして呼び出されていhandle_info/2ます。これらは、、またはご存知のように、のようなものを期待して{reply, ...}{noreply, ...}ます{stop, ...}

Remember that gen_server:cast/2 always returns ok and ServerPid ! Message always returns Message itself. That is why the first time you've been told {bad_return_value, ok} and the second time {bad_return_value, MessageSent}.

In your case I would stick with gen_server:cast way and simply put the right return value right after the erroneous call:

fs_outbound_controller:deallocate_me(UUID, self()),
{noreply, State}; %% strongly depends on what your logic there is
于 2012-11-15T18:40:22.353 に答える