Race condition in Roster.java

Hi,

We’re using openfire with our own custom presence plugin. Occasionally after adding a new user to an existing group we would find that sometimes (but not always) an existing client would start receiving presence status update messages from openfire for the new user without first receiving a “jabber:iq:roster” subscription message from openfire. The client would then ignore these presence status messages.

After a lengthy investigation I found what appears to be a race condition in Roster.java. If the openfire plugin calls “User.getRoster();” before the openfire main component has called Roster.addSharedUser then Roster.addSharedUser detects that “item.getSharedGroups().contains(group)” and returns without calling “broadcast(item, true);”.

To correct this I made the following change to roster creation in my copy of Roster.java. This appeared to correct the issue:

// Add the shared groups to the new roster item

for (Group group : groups) {

if (group.isUser(jid)) {

item.addSharedGroup(group);

itemGroups.add(group);

  •                     broadcast(item, true);
    

}

else {

item.addInvisibleSharedGroup(group);

}

There may be a more optimal way to fix this, but this change worked for me.

I took a look through the existing open jira issues but I didn’t see any matching issue. I was wondering if this is a known issue, and if not could we raise a jira to correct it?

Thanks…

Dave.
roster_race_fix2.patch.zip (400 Bytes)

Add your change as a patch file to your post. Then it can be attached to the Jira issue (OF-473).

Patch attached as requested, thanks!