summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2021-11-26 11:19:34 +0100
committerJan Lehnardt <jan@apache.org>2021-11-26 17:48:22 +0100
commit52a5612153dc1890284861146e35550a4af20add (patch)
tree2bbcd6faaf539f3b7f0f717876e48530be8956a1
parent9391bf0c0514dd81d2e0ea4d69b03cb1e2760606 (diff)
downloadcouchdb-fix/peruser2.tar.gz
fix memleak in couch_peruser, patch by @rnewsonfix/peruser2
-rw-r--r--src/couch_peruser/src/couch_peruser.erl20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/couch_peruser/src/couch_peruser.erl b/src/couch_peruser/src/couch_peruser.erl
index c87ffb2fb..480ad7ce8 100644
--- a/src/couch_peruser/src/couch_peruser.erl
+++ b/src/couch_peruser/src/couch_peruser.erl
@@ -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),
+ 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 ->
@@ -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};
@@ -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) ->