Browse Source

Demonitor in multi_call.

Roberto Ostinelli 3 years ago
parent
commit
847d8ea3e6
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/syn_pg.erl

+ 4 - 2
src/syn_pg.erl

@@ -223,7 +223,7 @@ multi_call(Scope, GroupName, Message, Timeout) ->
 
 
 -spec multi_call_reply({reference(), ClientPid :: pid()}, Reply :: term()) ->
 -spec multi_call_reply({reference(), ClientPid :: pid()}, Reply :: term()) ->
     {syn_multi_call_reply, reference(), Reply :: term()}.
     {syn_multi_call_reply, reference(), Reply :: term()}.
-multi_call_reply({Ref, CallerPid}, Reply) ->
+multi_call_reply({CallerPid, Ref}, Reply) ->
     CallerPid ! {syn_multi_call_reply, Ref, Reply}.
     CallerPid ! {syn_multi_call_reply, Ref, Reply}.
 
 
 %% ===================================================================
 %% ===================================================================
@@ -625,17 +625,19 @@ multi_call_and_receive(CollectorPid, Pid, Meta, Message, Timeout) ->
     MRef = monitor(process, Pid),
     MRef = monitor(process, Pid),
     %% send
     %% send
     Ref = make_ref(),
     Ref = make_ref(),
-    From = {Ref, self()},
+    From = {self(), Ref},
     Pid ! {syn_multi_call, Message, From, Meta},
     Pid ! {syn_multi_call, Message, From, Meta},
     %% wait for reply
     %% wait for reply
     receive
     receive
         {syn_multi_call_reply, Ref, Reply} ->
         {syn_multi_call_reply, Ref, Reply} ->
+            erlang:demonitor(MRef, [flush]),
             CollectorPid ! {syn_reply, Pid, Reply};
             CollectorPid ! {syn_reply, Pid, Reply};
 
 
         {'DOWN', MRef, _, _, _} ->
         {'DOWN', MRef, _, _, _} ->
             CollectorPid ! {syn_bad_reply, Pid}
             CollectorPid ! {syn_bad_reply, Pid}
 
 
     after Timeout ->
     after Timeout ->
+        erlang:demonitor(MRef, [flush]),
         CollectorPid ! {syn_bad_reply, Pid}
         CollectorPid ! {syn_bad_reply, Pid}
     end.
     end.