Smack: Roster#presenceChanged() failed to deliver all received <presence/> stanza status to the presenceChanged() listener

[20180604]
For me to get an estimate of the time taken for each of the <presence/> phrase, I included two log statements one before and another after the parseAndProcessStanza(parser);

                        switch (name) {
                            case Presence.ELEMENT:
                                LOGGER.log(Level.WARNING, "Received Stanza: " + name);
                                try {
                                    parseAndProcessStanza(parser);
                                } finally {
                                    clientHandledStanzasCount = SMUtils.incrementHeight(clientHandledStanzasCount);
                                }
                                LOGGER.log(Level.WARNING, "End of parse Stanza: " + name);
                                break;

I observed one strange behavior is that parseAndProcessStanza() does not always return from the current <presence/> stanza processing, look like it is locked in the endless loop waiting for the end tag; it only exit after it receives another new <presence/> stanza.

In my new test, with only two test accounts active i.e. test1(Note8) and test2(Note3), neither of them can see each other presence status, not matter what I do. Then I decided to add another third test account running on Ubuntu gajim (test3). After the third account has logged into the server, all the sudden the other two test accounts (test1 & test2) are now able to see each other presence statuses, including the third test3 account. The third active account seems to have helped to resync/flush out the the all packets for processing, but itself is also being consumed.

  1. Can it be possible that the <presence/> is out of sync or end tag is not flushed out, leading to the parsePresence(XmlPullParser parser) waiting in endless loop, until the end tag is pushed out, refilled? and resync by the next incoming <presence/> stanza. It seems this is the root cause based on test results and observation.

Below the is the log captured on Note 8:
When only two accounts are active (test1 and test2), the below log shows that although test2 <presence/> is received, but is does not return from parseAndProcessStanza(parser) processing;

06-04 17:47:33.411 20221-20320/org.atalk.android D/SMACK: RECV (0): <presence xmlns="jabber:client" id="m4uyY-179" from="test2@example.org/atalk">
       <status />
       <priority>30</priority>
       <x xmlns="vcard-temp:x:update" />
       <c xmlns="http://jabber.org/protocol/caps" node="http://android.atalk.org" hash="sha-1" ver="SPANeHrMhKxipyDRRXFZu1T21So=" />
    </presence>
06-04 17:47:33.414 20221-20320/org.atalk.android W/aTalk: [49736] org.jivesoftware.smack.tcp.XMPPTCPConnection.parsePackets() Received Stanza: presence
### missing: "End of parse Stanza: presence"

Upon test3 account login: then test1, test2 and test3 all can see each other presence. From the log, It is seen that the previous <presence/> stanza “End of parse Stanza: presence” is triggered by the new incomiong <presence/> stanza, but itself is also being consumed. Just by chance, the server actually sent test3 <presence/> stanza twice, the first one although is being consumed by the previous <presence/> stanza, the second test3 <presence/> allows it to be processed and shown in the contact list.

06-04 17:48:46.644 20221-20320/org.atalk.android D/SMACK: RECV (0): <presence xmlns="jabber:client" id="eeb210cd-cc3a-49ef-9f00-d230b350186c" from="test3@example.org/gajim.8UMM7OSE">
       <priority>50</priority>
       <x xmlns="vcard-temp:x:update">
          <photo />
       </x>
       <c xmlns="http://jabber.org/protocol/caps" node="http://gajim.org" hash="sha-1" ver="p44lDLrkpzGW+3RnMPI52AXyZCc=" />
    </presence>
06-04 17:48:46.663 20221-20320/org.atalk.android W/aTalk: [49736] org.jivesoftware.smack.tcp.XMPPTCPConnection.parsePackets() End of parse Stanza: presence
06-04 17:48:46.664 20221-20320/org.atalk.android D/SMACK: RECV (0): <presence xmlns="jabber:client" id="a64da9ba-d498-4c16-aebd-619a849bb5c6" from="test3@example.org/gajim.8UMM7OSE">
       <priority>50</priority>
       <x xmlns="vcard-temp:x:update">
          <photo />
       </x>
       <c xmlns="http://jabber.org/protocol/caps" node="http://gajim.org" hash="sha-1" ver="p44lDLrkpzGW+3RnMPI52AXyZCc=" />
    </presence>
06-04 17:48:46.672 20221-20320/org.atalk.android W/aTalk: [49736] org.jivesoftware.smack.tcp.XMPPTCPConnection.parsePackets() Received Stanza: presence
06-04 17:48:46.689 20221-20320/org.atalk.android W/aTalk: [49736] org.jivesoftware.smack.tcp.XMPPTCPConnection.parsePackets() End of parse Stanza: presence