Duplicate stanzas in unacknowledgedStanzas queue when stream is resumed

Hi, I’m using Smack 4.1.4 version.

When the stream is resumed and some stanzas have not been sent to the server, they are pushed from the **unacknowledgedStanzas queue **to the packet writer to be resent to the server, but this queue is not clean, so when the packet writer is going to send the stanza it stores the same one in **unacknowledgedStanzas queue **again. From this moment, the stanzas processed by server are not “ack” by client correctly.

The bug can be found in the packet reader, when it receives the resume stanza from server:

// Then re-send what is left in the unacknowledged queue
List stanzasToResend = new LinkedList();

stanzasToResend.addAll(unacknowledgedStanzas);

for (Stanza stanza : stanzasToResend) {

packetWriter.sendStreamElement(stanza);

}

I think we should clear the **unacknowledgedStanzas **queue before to resend the stanzas, something like this:

// Then re-send what is left in the unacknowledged queue
List stanzasToResend = new LinkedList();

unacknowledgedStanzas.drainTo(stanzasToResend);

unacknowledgedStanzas.addAllfor (Stanza stanza : stanzasToResend) {

packetWriter.sendStreamElement(stanza);

}

Regards.

Thanks for reporting. SMACK-700.

I’ve uploaded Smack 4.1.5-SNAPSHOT to the Maven Central snapshot repository, which includes https://github.com/Flowdalic/Smack/commit/d085e389e1914b1b051807d6b0a711fb1ba823 02 . Could you try and report back if it fixes the issue?

Test it. The issue is fixed. Only add one more thing.

In method** XMPPTCPConnection.processHandledCount() **an array list called ackedStanzas is created with the initial size of **handledCount **value. I think the initial value should be the **ackedStanzasCount **value. If we use the first value, and the XMPP session is long, the memory used by the array list can be so big to only ack a few of stanzas.

Right. Done. See https://github.com/Flowdalic/Smack/commit/cc758b8f591c9517571058b45ae0f888c64b2d d6

1 Like