Erlang:无法在另一个节点上启动主管

Erlang: Cannot start supervisor on another node

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

-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 上 运行 时,它工作得很好。但是现在我想 运行 这个主管在不同节点上的不同实例,称为 foo 和 bar(从 erl -sname fooerl -sname bar 开始,来自一个名为 main erl -sname main 的单独节点) .这就是我尝试启动此 rpc:call('foo@My-MacBook-Pro', a_sup, start_link, []). 的方式,但在回复 ok 后它立即失败并显示此消息

{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:

从消息来看,呼叫似乎希望主管成为 gen_server?当我尝试像这样在节点上启动 gen_server 时,它运行良好,但不适用于主管。我似乎无法弄清楚在 local/remote 节点上尝试启动主管是否有什么不同,如果是,我们应该如何解决这个问题?

根据@JoséM 的建议,远程节点中的主管也链接到临时 RPC 进程。但是由于supervisor没有提供start方法,修改start_link()方法为

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

问题已解决。