[erlang-questions] Weird pg2 behavior

Hans Bolinder hans.bolinder@REDACTED
Fri Apr 11 10:40:43 CEST 2008


[Matthew Dempsky:]
> We're seeing weird behavior with pg2, namely that dead pids are not
> getting cleared from the pg2:get_members table.  E.g.
> 
> 250> [X || X <- pg2:get_members(Group) --
> pg2:get_local_members(Group), node(X) =:= node()].
> [<0.795.0>,<0.794.0>,<0.793.0>,<0.792.0>,<0.791.0>,
>  <0.790.0>,<0.789.0>,<0.773.0>]
> 
> Am I correct that this is a bug in pg2?

It seems that pg2:leave() assumes that the pid is a member of the
group. The patch below should solve that problem ('ok' is returned if
the group exists but the pid is not a member of the group).

Best regards,

Hans Bolinder, Erlang OTP/team

*** /usr/local/otp/releases/otp_beam_solaris8_r12b_patched/lib/kernel-2.12.1.2/src/pg2.erl	Tue Mar  4 13:37:04 2008
--- pg2.erl	Tue Apr  8 09:53:10 2008
***************
*** 193,207 ****
                      node(Pid) =:= node() ->
                          [{_, LocalMembers}] = 
                              ets:lookup(pg2_table, {local_members, Name}),
!                         ets:insert(pg2_table,
!                                    {{local_members, Name},
!                                     lists:delete(Pid, LocalMembers)}),
!                         NLinks = lists:delete(Pid, S#state.links),
!                         case lists:member(Pid, NLinks) of
!                             true -> ok;
!                             false -> unlink(Pid)
!                         end,
!                         NLinks;
                      true ->
                          S#state.links
                  end,
--- 193,212 ----
                      node(Pid) =:= node() ->
                          [{_, LocalMembers}] = 
                              ets:lookup(pg2_table, {local_members, Name}),
!                         case lists:member(Pid, LocalMembers) of
!                             true ->
!                                 ets:insert(pg2_table,
!                                            {{local_members, Name},
!                                             lists:delete(Pid, LocalMembers)}),
!                                 NLinks = lists:delete(Pid, S#state.links),
!                                 case lists:member(Pid, NLinks) of
!                                     true -> ok;
!                                     false -> unlink(Pid)
!                                 end,
!                                 NLinks;
!                             false ->
!                                 S#state.links
!                         end;
                      true ->
                          S#state.links
                  end,



More information about the erlang-questions mailing list