From f0c32433dc057a83f0cddb04f34146e458cf4b6a Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Mon, 30 May 2011 16:51:55 +1000 Subject: [PATCH] Fix race condition (EJABS-1677) --- src/mod_ack.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mod_ack.erl b/src/mod_ack.erl index 68606283f..7268b549e 100644 --- a/src/mod_ack.erl +++ b/src/mod_ack.erl @@ -233,8 +233,16 @@ handle_cast(_Msg, State) -> handle_info({timeout, _TRef, {ID, Pid}}, State) -> case lookup(Pid, ID, State#state.timers) of {ok, _} -> - catch ejabberd_c2s:stop(Pid), - handle_cast({del, Pid}, State); + MRef = erlang:monitor(process, Pid), + catch ejabberd_c2s:stop(Pid), + receive + {'DOWN', MRef, process, Pid, _Reason}-> + ok + after 5 -> + catch exit(Pid, kill) + end, + erlang:demonitor(MRef, [flush]), + handle_cast({del, Pid}, State); error -> {noreply, State} end;