Erlang:无法在另一个节点上启动超级用户

ny6fqffe  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(146)

我有一个简单的主管,看起来像这样

-module(a_sup).
-behaviour(supervisor).

%% API
-export([start_link/0, init/1]).

start_link() ->
  supervisor:start_link({local,?MODULE}, ?MODULE, []).

init(_Args) ->
  RestartStrategy = {simple_one_for_one, 5, 3600},
  ChildSpec = {
    a_gen_server,
    {a_gen_server, start_link, []},
    permanent,
    brutal_kill,
    worker,
    [a_gen_server]
  },
  {ok, {RestartStrategy,[ChildSpec]}}.

当我在shell上运行这个命令时,它运行得非常好。但是现在我想在不同的节点上运行这个supervisor的不同示例,名为foo和bar(从一个名为main erl -sname main的单独节点开始,以erl -sname fooerl -sname bar启动)。

{ok,<9098.117.0>}
=ERROR REPORT==== 7-Mar-2022::16:05:45.416820 ===
** Generic server a_sup terminating 
** Last message in was {'EXIT',<9098.116.0>,
                               {#Ref<0.3172713737.1597505552.87599>,return,
                                {ok,<9098.117.0>}}}
** When Server state == {state,
                            {local,a_sup},
                            simple_one_for_one,
                            {[a_gen_server],
                             #{a_gen_server =>
                                   {child,undefined,a_gen_server,
                                       {a_gen_server,start_link,[]},
                                       permanent,false,brutal_kill,worker,
                                       [a_gen_server]}}},
                            {maps,#{}},
                            5,3600,[],0,never,a_sup,[]}
** Reason for termination ==
** {#Ref<0.3172713737.1597505552.87599>,return,{ok,<9098.117.0>}}

(main@Prachis-MacBook-Pro)2> =CRASH REPORT==== 7-Mar-2022::16:05:45.416861 ===
  crasher:
    initial call: supervisor:a_sup/1
    pid: <9098.117.0>
    registered_name: a_sup
    exception exit: {#Ref<0.3172713737.1597505552.87599>,return,
                     {ok,<9098.117.0>}}
      in function  gen_server:decode_msg/9 (gen_server.erl, line 481)
    ancestors: [<9098.116.0>]
    message_queue_len: 0
    messages: []
    links: []
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 610
    stack_size: 29
    reductions: 425
  neighbours:

从消息中看,这个调用似乎希望supervisor是一个gen_server?当我尝试在节点上初始化一个gen_server时,它运行得很好,但对于supervisor就不行了。我似乎不知道在本地/远程节点上初始化supervisor是否有什么不同,如果有,我们应该怎么做来解决这个问题?

izkcnapc

izkcnapc1#

按照@JoséM的建议,远程节点中的supervisor也链接到临时RPC进程。

start_link() ->
  Pid = supervisor:start_link({local,?MODULE}, ?MODULE, []).
  unlink(Pid),
  {ok, Pid}.

解决了这个问题。

相关问题