* Here is the scenario, correct me if my assumptions are wrong:
* user1@d1 connects with resource r1, finishes resource bind, session bind, roster fetch and initial presence update. One entry for its c2s process is made in "session" table, during session binding phase.
* user1@d1 from another client connects with resource r1, finishes resource binding and sends session bind packet, then...
* "ejabberd_sm:open_session" get called for the 2nd connection. Which internally looks up session table, finds 1st connection with same resource and then sends "replace" message to it. And gives ack to 2nd connection that resource binding is successful.
* The problem here is that the "replace" message might not get processed for 1st connection before the initial presence broadcast for 2nd connection. And contacts of this user might incorrectly see him as offline.
* I have not seen any code that does some explicit sync to avoid such problem. Is this a known issue?
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.
let me know if further clarification is needed to understand the problem.
Yes, problem exists
The problem here is that the "replace" message might not get processed for 1st connection before the initial presence broadcast for 2nd connection.
I have not seen any code that does some explicit sync to avoid such problem.
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.
And contacts of this user might incorrectly see him as offline.
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.
Right. To allow easier reproduction and debugging of the problem, I apply this patch:
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.
This is logged by ejabberd:
This is what user2 receives:
Consequently, the user2 client shows user1 as offline, but in reality he is online!
Is this a known issue?
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.
If implementing an order-verification feature is too difficult, the simple workaround would be to implementOption to disallow new session if resource conflict , which doesn't have that problem. And enable that option in the default ejabberd.cfg.
Thanks for the detailed
Thanks for the detailed response. This was a great help in verifying that I do understand ejabberd code correctly.
Also the workaround of keeping older connection alive for a given resource is something I had never considered.
Thanks.