【问题标题】:An error with Erlang routerErlang 路由器出错
【发布时间】:2012-11-01 08:08:22
【问题描述】:

我尝试使用 Mochiweb 制作一个彗星服务器,例如 there

如果我从 erlang shell 中执行,没关系。

但是如果尝试从命令行使用 mochiweb 启动第一个节点:

erl -pa ebin edit deps/*/ebin -boot start_sasl -sname n1 -s server +K true -setcookie secret_key -s reloader

第二个带路由器:

erl -pa ebin edit deps/*/ebin -boot start_sasl -sname router -setcookie secret_key -eval 'net_adm:ping(n1@localhost), router:start_link().'

如果我从浏览器连接到 mochiweb,则会出现此错误

=CRASH REPORT==== 18-Jul-2012::19:04:45 ===
crasher:
initial call: mochiweb_acceptor:init/3
pid: <0.73.0>
registered_name: []
exception exit: {noproc,
                    {gen_server,call,
                        [undefined,{login,"234567e",<0.73.0>}]}}
  in function  gen_server:call/2
  in call from server_web:loop/2
  in call from mochiweb_http:headers/5
ancestors: [server_web,server_sup,<0.55.0>]
messages: []
links: [<0.57.0>,#Port<0.1406>]
dictionary: [{mochiweb_request_qs,
                  [{"session_id","234567e"},{"obj_id","page"}]},
              {mochiweb_request_path,"/polling"}]
trap_exit: false
status: running
heap_size: 2584
stack_size: 24
reductions: 1516

我认为问题出在 router.erl 的这个字符串中:

-define(SERVER, global:whereis_name(?MODULE)).

因为 -eval (net_adm:ping(n1@localhost)) 的第一部分启动时没有错误,我可以在 nodes( )。。但是 -eval 的第二部分 (router:start_link()) 不适用于 ?MODULE

我该如何解决这个问题?

【问题讨论】:

    标签: erlang router mochiweb


    【解决方案1】:

    看起来应该使用当前模块的名称全局注册的 gen_server(?MODULE 被替换为它)尚未启动。在这种情况下,global:whereis_name(?MODULE) 将返回 undefined,就像您在发布的日志中看到的那样。

    找到应该执行此操作的代码部分(通过在该模块中查找 ?MODULe 和/或 gen_server:start_link)并确保它在第一个节点上执行。

    【讨论】:

      猜你喜欢
      • 2016-07-15
      • 2017-09-25
      • 2020-06-28
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2023-03-12
      • 2020-12-29
      相关资源
      最近更新 更多