Can not set nick when add roster sometimes

The packets that I sent to the ejabberd are as followings:

2015-07-03 10:19:24:144 pigai[36644:3a0b] The nick is songxiao
2015-07-03 10:19:24:144 pigai[36644:3a0b] SEND: <iq type="set" xmlns="jabber:client" id="roster-remotely-managed"><query xmlns="jabber:iq:roster"><item jid="xh1@192.168.1.67" name="songxiao"/></query></iq>
2015-07-03 10:19:24:144 pigai[36644:800b] SEND: <presence type="subscribe" to="xh1@192.168.1.67"><x xmlns="vcard-temp:x:update"><photo>c769b958f910fb6bfde4e8131385cc5ad2d95e0b</photo></x></presence>
2015-07-03 10:19:24:576 pigai[36644:3a0b] RECV: <iq xmlns="jabber:client" from="test3@192.168.1.67" to="test3@192.168.1.67/iPhone" id="push2270407375" type="set"><query xmlns="jabber:iq:roster" ver="6e3b72a923e4574fac87e8e89f08eee251cf73c8"><item subscription="none" name="songxiao" jid="xh1@192.168.1.67"/></query></iq>
2015-07-03 10:19:24:576 pigai[36644:3a0b] RECV: <r xmlns="urn:xmpp:sm:3"/>
2015-07-03 10:19:24:576 pigai[36644:3a0b] RECV: <iq xmlns="jabber:client" from="test3@192.168.1.67" to="test3@192.168.1.67/iPhone" id="roster-remotely-managed" type="result"/>
2015-07-03 10:19:24:577 pigai[36644:3a0b] RECV: <r xmlns="urn:xmpp:sm:3"/>
2015-07-03 10:19:24:577 pigai[36644:3a0b] RECV: <iq xmlns="jabber:client" from="test3@192.168.1.67" to="test3@192.168.1.67/iPhone" id="push2639732641" type="set"><query xmlns="jabber:iq:roster" ver="b16ad5f42baf7c0fe11925ed879ac7ecb0bcfb85"><item ask="subscribe" subscription="none" jid="xh1@192.168.1.67"/></query></iq>
2015-07-03 10:19:26:602 pigai[36644:433] RECV: <r xmlns="urn:xmpp:sm:3"/>
2015-07-03 10:19:26:602 pigai[36644:433] SEND: <a xmlns="urn:xmpp:sm:3" h="15"/>
2015-07-03 10:19:26:808 pigai[36644:4b17] SEND: <a xmlns="urn:xmpp:sm:3" h="15"/>

The nick was not set. From the client side, the nick is null. From the server side, the nick is not stored.
But sometimes the nick can be set, sometimes the nick can not be set. The iq that I sent are the same.

any ideas?

any ideas?

Because I send an IQ and

Because I send an IQ and Presence to server at the same time. I guess the server may handle the two messages in wrong sequence. Maybe the server is handling the IQ writing the nick to database, but not finished. Then handle the Presence while reading the nick from the database, but there is no nick there. Maybe it is not thread-safe? Btw, I am using MySql as the database.

Here is a sequence that

Here is a sequence that should work fine:

1. Send the presence subscribe.
2. Wait for reply.
3. Set the name on roster item.

We will have a look to see if we can improve to handle this case better as well.

Syndicate content