Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/couch_peruser/src/couch_peruser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

-spec init_state() -> #state{}.
init_state() ->
reset_state(#state{mem3_cluster_pid = Pid} = State) when is_pid(Pid) ->
unlink(Pid),
Copy link
Contributor

@nickva nickva Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we just unlink the process, but the process would still be alive and we'd be accumulating them and each one would still be sending stable|unstable events. The memleak is not from the links themselves but from the number of processes spawned.

reset_state(State#state{mem3_cluster_pid = undefined});
reset_state(State) ->
couch_log:debug("peruser: starting on node ~p in pid ~p", [node(), self()]),
case config:get_boolean("couch_peruser", "enable", false) of
false ->
Expand Down Expand Up @@ -445,7 +447,7 @@ cluster_stable(Server) ->
-spec init(Options :: list()) -> {ok, #state{}}.
init([]) ->
ok = subscribe_for_changes(),
{ok, init_state()}.
{ok, reset_state(#state{})}.

handle_call(is_stable, _From, #state{cluster_stable = IsStable} = State) ->
{reply, IsStable, State};
Expand All @@ -454,16 +456,16 @@ handle_call(_Msg, _From, State) ->

handle_cast(update_config, State) when State#state.states =/= undefined ->
exit_changes(State),
{noreply, init_state()};
handle_cast(update_config, _) ->
{noreply, init_state()};
{noreply, reset_state(State)};
handle_cast(update_config, State) ->
{noreply, reset_state(State)};
handle_cast(stop, State) ->
{stop, normal, State};
handle_cast(cluster_unstable, State) when State#state.states =/= undefined ->
exit_changes(State),
{noreply, init_state()};
handle_cast(cluster_unstable, _) ->
{noreply, init_state()};
{noreply, reset_state(State)};
handle_cast(cluster_unstable, State) ->
{noreply, reset_state(State)};
handle_cast(cluster_stable, State) ->
{noreply, start_listening(State)};
handle_cast(_Msg, State) ->
Expand Down