powered by Jive Software

Receiving lost, unordered and duplicate messages at stream resumption


I am using Smack 4.1.1 on Android with Tigase version 7.0.1 have the attached logic

for setting up the connection & login. When I disable the connection on Android device,

ReconnectionManager comes into play & successfully obtains the connection when I

re-enable the connection. During the period, the current device(i.e. the receiver) is offline,

if the sender sends messages(actual text) 1,2,3,4,5,6 on enabling the connection for receiver

messages 1,6,4,4,2,6 are received in the order written. I have tried this many times but the

order remains jumbled with duplicates. Although the number of messages received is always

same as the number of messages sent by the sender.

From server logs, it is clear that the server is correctly resuming the stream & is sending the

messages back in the right order with no message loss or duplication which implies that there

is something wrong with my logic. Can someone please take a look & guide.

static {




SmackConfiguration.DEBUG = true;

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration








XMPPTCPConnection connection = new XMPPTCPConnection(config);



StanzaFilter filter = MessageTypeFilter.CHAT;

connection.addAsyncStanzaListener(new StanzaListener() {


public void processPacket(Stanza packet) {



}, filter);

connection.login(username, password, resource);

Presence presence = new Presence(Presence.Type.available);





connection.addAsyncStanzaListener(new StanzaListener() {

Don’t use an async stanza listener if the order is important. Use a sync one.

Async listeners are potentially invoked concurrently, so the order is not kept. While this does not explain the duplicates, I suggest you try a sync listener and report back.

1 Like

Thanks a lot. SyncStanzaListener seems to be taking care of the issues.

What is AsyncStanzaListener for then ?

There are use cases where you don’t care about the order. And async stanza listener does not block the “main incoming stanza processing threading”.

In some cases all the messages received in a session before disconnect are being received again, this is happening pretty regularly(no message loss or order issue though). Is it because somehow the acknowledgement status of messages delivered previously is getting reset ?

It’s most likely because the SM ack for those messages was not received by the other party.

Thanks, if the acknowledgements didn’t reach SM, what Smack API methods/logic should I add

to detect which acknowledgements didn’t reach the server & how to make sure that they get re-sent

when the network connection is enabled.

they get re-sent when the network connection is enabled.

That’s done automatically by Smack.

Does that mean that there is some bug in API code(I am using 4.1.1) as I see

duplicates on stream resumption. Please let me know if I should trace the specific

part of API code which deals with this situation. I also noticed the methods,

sendSmAcknowledgement() & requestSmAcknowledgement() under XMPPTCPConnection

class. Will calling one of these on connection resumption would help ?

Does that mean that there is some bug
No, stream management, if resumption fails, can’t guarantee that there will be no duplicates. If an ack got lost, but the stanzas got received just before the stream got interrupted, the stanzas will (eventually) be resend if SM resumption fails, causing duplication.

Edit: I just read that you wrote “on SM resumption”. If that’s the case, then it’s possible to be a bug. But without a XMPP trance it’s hard to tell. Please look at https://github.com/igniterealtime/Smack/wiki/How-to-ask-for-help-or-report-an-is sue

Thanks for the information. I will retry & report the issue with details.

Hello, what if I use class extended by ChatMessageListener to receive messages and get duplicated messages. What can I do?

Working like a charm!!