Question

I have a simple server (below). I can create the server with cell_tracer:start_link() and this works; I know this because when I repeat the same call, I get an already_started error. The problem is that after the server is created, using cell_tracker:get_cells() (or doing any gen_server:call(...)) on it causes the server to exit with an exception like this:

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

I can call the handle_call(get_cells...) directly, and I get the expected result.

I'm not sure what's happening here. It doesn't give me much information to work with, and I don't see a problem. How can I dig into this further?

-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}.
Was it helpful?

Solution

register the server locally

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

or if you register {global, ?MODULE} cast, call to {global, ?MODULE}

see gen_server

OTHER TIPS

I have got the same problem working with python ( 2.7 ) and couchdb ( 2.1 ). The point was I did save document without id. Here is an example

import couchdb
server = couchdb.Server('http://admin:PASSWORD@127.0.0.1:5984/')
db = server.create('numbers')
idd, revv = db.save({"taras":"vaskiv"})

after this I got this exception

431         # Store cachable responses
ServerError: (500, (u'noproc', u'{gen_server,call,[couch_uuids,create]}'))

But when I did save document with id, everything seems to work just fine.

idd, revv = db.save({"taras":"vaskiv", "_id": "55"})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top