uwiger / gproc

Extended process registry for Erlang
Apache License 2.0
1.07k stars 232 forks source link

What could be the reason for this crash? #15

Closed burinov closed 11 years ago

burinov commented 12 years ago

In code I very often call gproc like this:

handle_cast({msg, To, Message}, State) ->
    spawn(fun() -> 
            % Trying to lookup Pid from gproc
            case gproc:lookup_local_name(To) of
                undefined ->
                    % player is not loaded, loading the player
                    player:start(To, Message);
                Pid ->
                    % player is here, passing the message to him
                    gen_server:cast(Pid, Message)
            end 
        end),
    {noreply, State};
handle_cast(_Msg, State) ->
    {noreply, State}.

In module player I work with grpoc like this:

init([Name]) ->
    % Registering in gproc
    ?LOG("Creating new process", Name),
    gproc:add_local_name(Name),
    {ok, #state{name = Name, ready = 0}}.

From time to time I see something like this in my logs:

=CRASH REPORT==== 8-Jan-2012::01:50:52 ===
  crasher:
    initial call: player:init/1
    pid: <0.19872.4>
    registered_name: []
    exception exit: {badarg,[{gproc,chk_reply,
                                    {reg,{n,l,"player560"},undefined}},
                             {player,init,1},
                             {gen_server,init_it,6},
                             {proc_lib,init_p_do_apply,3}]}
      in function  gen_server:init_it/6
    ancestors: [<0.19870.4>]
    messages: []
    links: []
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 377
    stack_size: 24
    reductions: 164
  neighbours:

What could be the reason for this? Is this because of gproc of my code?

uwiger commented 12 years ago

Hi Max,

The most likely reason I can think of is that {n,l,"player560"} is already registered. I don't have any other suggestion.

If the name is taken by another process after a crash, there is a (remote) possibility that the gproc server hasn't had time to remove the old registration, but if the new process is started by a supervisor reacting to the death of the first process, gproc will have received the DOWN message at the same time...

BR, Ulf W

2012/1/8 Max Burinov < reply@reply.github.com

In code I very often call gproc like this:

handle_cast({msg, To, Message}, State) -> spawn(fun() -> % Trying to lookup Pid from gproc case gproc:lookup_local_name(To) of undefined -> % player is not loaded, loading the player player:start(To, Message); Pid -> % player is here, passing the message to him gen_server:cast(Pid, Message) end end), {noreply, State}; handle_cast(_Msg, State) -> {noreply, State}.

In module player I work with grpoc like this:

init([Name]) -> % Registering in gproc ?LOG("Creating new process", Name), gproc:add_local_name(Name), {ok, #state{name = Name, ready = 0}}.

From time to time I see something like this in my logs:

=CRASH REPORT==== 8-Jan-2012::01:50:52 === crasher: initial call: player:init/1 pid: <0.19872.4> registered_name: [] exception exit: {badarg,[{gproc,chk_reply, {reg,{n,l,"player560"},undefined}}, {player,init,1}, {gen_server,init_it,6}, {proc_lib,init_p_do_apply,3}]} in function gen_server:init_it/6 ancestors: [<0.19870.4>] messages: [] links: [] dictionary: [] trap_exit: false status: running heap_size: 377 stack_size: 24 reductions: 164 neighbours:

What could be the reason for this? Is this because of gproc of my code?


Reply to this email directly or view it on GitHub: https://github.com/uwiger/gproc/issues/15