0
votes

I have Xmpp stack based on Ejabberd(version 16.04) and Smack client library(4.17 on Android).

I'm facing a situation where messages sent by server get dropped, when the client goes offline temporarily. Here are the steps I use to replicate the situation, along with the logs from ejabberd.

1- Client A goes online

2016-06-19 01:22:59.834 [info] <0.505.0>@ejabberd_listener:accept:333 (#Port<0.19955>) Accepted connection 122.172.241.21:26683 -> 139.162.34.247:5222
2016-06-19 01:23:00.449 [info] <0.667.0>@ejabberd_c2s:wait_for_sasl_response:900 ({socket_state,gen_tcp,#Port<0.19955>,<0.666.0>}) Accepted authentication for 9739937980 by undefined from 122.172.241.21
2016-06-19 01:23:00.619 [info] <0.667.0>@ejabberd_c2s:open_session:1111 ({socket_state,gen_tcp,#Port<0.19955>,<0.666.0>}) Opened session for [email protected]/Smack
2016-06-19 01:23:00.698 [info] <0.667.0>@ejabberd_c2s:handle_enable:2700 Stream management with resumption enabled for [email protected]/Smack

2 - Client A is disconnected uncleanly(wifi disconnected or app is killed)

2016-06-19 01:27:57.582 [info] <0.667.0>@ejabberd_c2s:fsm_next_state:2454 Waiting for resumption of stream for [email protected]/Smack

3 - Other client/bots send message to client A

4 - Client A comes back on line after a short while( 60 seconds)

2016-06-19 01:28:39.367 [info] <0.505.0>@ejabberd_listener:accept:333 (#Port<0.19963>) Accepted connection 122.172.241.21:26543 -> 139.162.34.247:5222
2016-06-19 01:28:40.050 [info] <0.684.0>@ejabberd_c2s:wait_for_sasl_response:900 ({socket_state,gen_tcp,#Port<0.19963>,<0.683.0>}) Accepted authentication for 9739937980 by undefined from 122.172.241.21
2016-06-19 01:28:40.213 [info] <0.684.0>@ejabberd_c2s:open_session:1111 ({socket_state,gen_tcp,#Port<0.19963>,<0.683.0>}) Opened session for [email protected]/Smack
2016-06-19 01:28:40.214 [info] <0.667.0>@ejabberd_c2s:terminate:1758 ({socket_state,gen_tcp,#Port<0.19955>,<0.666.0>}) Replaced session for [email protected]/Smack
2016-06-19 01:28:40.215 [info] <0.667.0>@ejabberd_c2s:handle_unacked_stanzas:2872 2 stanzas were not acknowledged by [email protected]/Smack
2016-06-19 01:28:40.302 [info] <0.684.0>@ejabberd_c2s:handle_enable:2700 Stream management with resumption enabled for [email protected]/Smack

Now, here ejabberd tells me that it hasn't received acknowledgement for pending messages 2 stanzas were not acknowledged by [email protected]/Smack. Moreover, the messages are not received by Smack library and are dropped.

So obviously, Smack client library is not sending proper acks for the messages after reconnecting. I've tried enabling Stream Management(XEP-198) in my client library code, but its not working. My Smack client connection code looks like:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
            .builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setServiceName(serverAddress);
config.setHost(serverAddress);
config.setPort(5222);
config.setDebuggerEnabled(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
connection = new XMPPTCPConnection(config.build());
connection.setUseStreamManagement(true);
connection.setUseStreamManagementResumption(true);

What changes do I need to avoid those dropped messages?

Thanks.

1

1 Answers

1
votes

I figured it out myself.

There was a bug in my client side code. I was adding ChatMessageListener to the connection very late.

So even though ejabberd was re-sending the messages correctly on resume, without ChatMessageListener those messages were not being acked properly or stored to client side database.