ejabberd - Comments for "Replacing old sessions with same resource and its impact on unavailable presence" https://www.ejabberd.im/node/3991 en Thanks for the detailed https://www.ejabberd.im/node/3991#comment-55591 <p>Thanks for the detailed response. This was a great help in verifying that I do understand ejabberd code correctly.</p> <p>Also the workaround of keeping older connection alive for a given resource is something I had never considered. </p> <p>Thanks.</p> Sat, 17 Apr 2010 16:34:12 +0000 Jigar Gosar comment 55591 at https://www.ejabberd.im Yes, problem exists https://www.ejabberd.im/node/3991#comment-55517 <div class="quote-msg"> <div class="quote-author"><em>Jigar Gosar</em> wrote:</div> <p>The problem here is that the "replace" message might not get processed for 1st connection before the initial presence broadcast for 2nd connection.</p> <p>I have not seen any code that does some explicit sync to avoid such problem. </p></div> <p>In general, that problem doesn't happen; otherwise it would have been already reported in the bug tracker. But in rare cases it might happen. I didn't find any code that ensures the presence ordering you refer.</p> <div class="quote-msg"> <div class="quote-author"><em>Jigar Gosar</em> wrote:</div> <p>And contacts of this user might incorrectly see him as offline.</p> <p>p.s.: if directed unavailable presence broadcast of the 1st connection happens after 2nd connection joins a conf room, than conf-room might mistakenly log off 2nd connection. </p></div> <p>Right. To allow easier reproduction and debugging of the problem, I apply this patch:</p> <pre> --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -1373,6 +1373,8 @@ terminate(_Reason, StateName, StateData) -&gt; StateData#state.server, StateData#state.resource, "Replaced by new connection"), + timer:sleep(5000), + ?INFO_MSG("Broadcast unavailable presence of old~n~p", [StateData#state.socket]), presence_broadcast( StateData, From, StateData#state.pres_a, Packet), presence_broadcast( @@ -1836,6 +1838,7 @@ presence_broadcast_to_trusted(StateData, From, T, A, Packet) -&gt; presence_broadcast_first(From, StateData, Packet) -&gt; + ?INFO_MSG("Broadcast initial presence of new socket~n~p", [StateData#state.socket]), ?SETS:fold(fun(JID, X) -&gt; ejabberd_router:route( From, </pre><p> First I login to user1@localhost/home and user2@localhost/work, which are mutual contacts. Then I login with another client to user1@localhost/home.</p> <p>This is logged by ejabberd:</p> <pre> =INFO REPORT==== 7-Apr-2010::23:53:04 === I(&lt;0.319.0&gt;:ejabberd_c2s:1841) : Broadcast initial presence of new socket {socket_state,gen_tcp,#Port&lt;0.3891&gt;,&lt;0.318.0&gt;} =INFO REPORT==== 7-Apr-2010::23:53:08 === I(&lt;0.313.0&gt;:ejabberd_c2s:1377) : Broadcast unavailable presence of old {socket_state,gen_tcp,#Port&lt;0.3853&gt;,&lt;0.312.0&gt;} </pre><p> This is what user2 receives:</p> <pre> &lt;presence from='user1@localhost/home' to='user2@localhost/work'&gt; &lt;show&gt;xa&lt;show&gt; &lt;priority&gt;8&lt;priority&gt; &lt;presence&gt; &lt;presence from='user1@localhost/home' to='user2@localhost/work' type='unavailable'&gt; &lt;status&gt;Replaced by new connection&lt;status&gt; &lt;presence&gt; </pre><p>Consequently, the user2 client shows user1 as offline, but in reality he is online!</p> <div class="quote-msg"> <div class="quote-author"><em>Jigar Gosar</em> wrote:</div> <p>Is this a known issue? </p></div> <p>I haven't found any ticket about this, so this is a newly found problem. If you have nothing more to add in the next days, I'll submit a new ticket next week.</p> <p>If implementing an order-verification feature is too difficult, the simple workaround would be to implement <noindex><a href="https://support.process-one.net/browse/EJAB-650" rel="nofollow" >Option to disallow new session if resource conflict</a></noindex>, which doesn't have that problem. And enable that option in the default ejabberd.cfg.</p> Wed, 07 Apr 2010 22:14:00 +0000 mfoss comment 55517 at https://www.ejabberd.im