summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2017-07-11 10:43:28 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2017-07-11 14:28:48 -0400
commitcc668ba7b67b27369720fa3b9cac6844c698f1a0 (patch)
treefed3415e65359f4efdf7fac37c4024779c437577
parent34b803a35531f305e05080c35c3e9af9e3b9dbf2 (diff)
downloadcouchdb-cc668ba7b67b27369720fa3b9cac6844c698f1a0.tar.gz
Make couch_event_sup:stop/1 synchronous
Because `stop/1` is asynchronous, and casts a stop message and as result the client process could end getting killed during termination/cleanup phase if this sequence of events took place: 1. Client calls `stop(ListerPid).` 2. couch_event_sup casts a `stop` message to couch_event_sup gen_server 3. `stop` message is delayed and client continues executing. 4. Client calls something like application:stop/1`. 5. `application:stop/1` terminates couch_event_sup gen_server. 6. App termination kills client process because it is still linked. So this make the stop synchrounous by using call instead of cast. Issue #644
-rw-r--r--src/couch/src/couch_event_sup.erl10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/couch/src/couch_event_sup.erl b/src/couch/src/couch_event_sup.erl
index b617498df..32f1b9b68 100644
--- a/src/couch/src/couch_event_sup.erl
+++ b/src/couch/src/couch_event_sup.erl
@@ -48,7 +48,7 @@ start_link(ServerName, EventMgr, EventHandler, Args) ->
gen_server:start_link(ServerName, couch_event_sup, {EventMgr, EventHandler, Args}, []).
stop(Pid) ->
- gen_server:cast(Pid, stop).
+ gen_server:call(Pid, stop).
init({EventMgr, EventHandler, Args}) ->
case gen_event:add_sup_handler(EventMgr, EventHandler, Args) of
@@ -61,11 +61,11 @@ init({EventMgr, EventHandler, Args}) ->
terminate(_Reason, _State) ->
ok.
-handle_call(_Whatever, _From, State) ->
- {reply, ok, State}.
+handle_call(stop, _From, State) ->
+ {stop, normal, ok, State}.
-handle_cast(stop, State) ->
- {stop, normal, State}.
+handle_cast(_Msg, State) ->
+ {noreply, State}.
handle_info({gen_event_EXIT, _Handler, Reason}, State) ->
{stop, Reason, State}.