gen_server:调用导致服务器与noproc崩溃

Sha*_*off 3 erlang erlang-otp

我有一个简单的服务器(下面).我可以创建服务器,cell_tracer:start_link()这是有效的; 我知道这个,因为当我重复同一个电话时,我收到一个already_started错误.问题是在创建服务器之后,使用cell_tracker:get_cells()(或执行任何操作gen_server:call(...))导致服务器退出时出现如下异常:

** exception exit: {noproc,{gen_server,call,[cell_tracker,get_cells]}}
     in function  gen_server:call/2 (gen_server.erl, line 180)
Run Code Online (Sandbox Code Playgroud)

我可以handle_call(get_cells...)直接打电话,我得到了预期的结果.

我不确定这里发生了什么.它没有给我很多信息,我没有看到问题.我该如何进一步深入研究?

-module(cell_tracker).
-behavior(gen_server).
-export([start_link/0, stop/0]).
-export([add_cell/1, del_cell/1, get_cells/0]).
-export([init/1,
         handle_cast/2,
         handle_call/3,
         terminate/2,
         handle_info/2,
         code_change/3]).

%% operational api
start_link() ->
  gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).

stop() ->
  gen_server:cast(?MODULE, stop).

%% traking api

add_cell(Cell) ->
  gen_server:call(?MODULE, { add_cell, Cell }).

del_cell(Cell) ->
  gen_server:call(?MODULE, { del_cell, Cell }).

get_cells() ->
  gen_server:call(?MODULE, get_cells).

%% gen_server callbacks

init(Coords) ->
  {ok, Coords}.

handle_cast(stop, Coords) ->
  {stop, normal, Coords}.

handle_call({add_cell, Cell}, _From, Cells) ->
  {reply, ok, [Cell|Cells]};
handle_call({del_cell, Cell}, _From, Cells) ->
  {reply, ok, Cells -- Cell};
handle_call(get_cells, _From, Cells) ->
  {reply, Cells, Cells}.

terminate(unnormal, _State) -> ok.

handle_info(_,_) -> ok.
code_change(_,State,_) -> {ok, State}.
Run Code Online (Sandbox Code Playgroud)

loc*_*jay 6

在本地注册服务器

start_link() ->
  gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
Run Code Online (Sandbox Code Playgroud)

或者如果您注册{global, ?MODULE}演员,请致电{global, ?MODULE}

gen_server