tigase-server
tigase-server copied to clipboard
Undelivered stanzas are processed before stream closure commands
Describe the bug
There is a race condition between STREAM_CLOSED, STREAM_FINISHED command stanzas and processing undelivered stanzas.
When the connection is closed tigase.server.xmppclient.StreamManagementIOProcessor#serviceStopped method is called.
tigase.server.xmppclient.StreamManagementIOProcessor#serviceStopped calls;
tigase.server.xmppclient.ClientConnectionManager#serviceStopped->tigase.server.xmppclient.ClientConnectionManager#xmppStreamClosedto create and sendSTREAM_CLOSED,STREAM_FINISHEDstanzastigase.server.xmppclient.StreamManagementIOProcessor#sendErrorsForQueuedPackets->tigase.server.xmppclient.ClientConnectionManager#processUndeliveredPacketto process undelivered stanzas
After creatingSTREAM_CLOSED, STREAM_FINISHED stanzas, they are started to process by calling addOutPacket however undelivered stanzas are started to process by calling processOutPacket.
Somehow, the first undelivered stanza processed before STREAM_CLOSED, STREAM_FINISHED stanzas in SessionManager. The first undelivered stanza includes delivery-error element that is processed by Message forwarder tigase.xmpp.impl.Message#preProcess and then tigase/xmpp/impl/C2SDeliveryErrorProcessor#preProcess filter stanza when it finds XMPPResourceConnection.
To Reproduce Send bulk messages to the receiver. The receiver disconnects before not sending the acknowledgment to all of the stanzas
Impact Undelivered stanza processing is blocked by the Message forwarder and does not go through to offline messages. It causes the message lost.
[1;92m[2022-12-27 08:05:24:390][0;36m [FINEST ][0m [ in_20-sess-man ][1;34m SessionManager.processPacket() : [0mPacket blocked by: message, packetfrom=c2s@internal/10.10.10.10_5222_192.168.255.255_61068, to=sess-man@internal, DATA=<message from="[email protected]/5964a0422a5b938a" to="[email protected]" xmlns="jabber:client" type="chat" id="gPHAlLqtwVnAoAKaFJm2o6PxbAjjbj"><group id="HY0FD" xmlns="http://kontalk.org/extensions/message#group"><nick xmlns="http://jabber.org/protocol/nick">Nick-d6ce</nick><body>Message 13</body><active xmlns="http://jabber.org/protocol/chatstates"/></group><delay xmlns="urn:xmpp:delay" stamp="2022-12-27T08:05:22.599Z" from="mydomain.com"/><delivery-error stamp="1672128322599" xmlns="http://tigase.org/delivery-error"/></message>, SIZE=623, XMLNS=jabber:client, PRIORITY=NORMAL, PERMISSION=NONE, TYPE=chat
Expected behavior
We have to ensure STREAM_CLOSED, STREAM_FINISHED stanzas are processed before the undelivered stanza.
Screenshots NA
Details (please complete the following information):
- Tigase version: 8.1.0
- JVM flavour and version : openjdk 11.0.7 2020-04-14
- Operating system/distribution/version : Ubuntu 18.04.1 LTS
- INTEL(R) XEON(R) PLATINUM 8259CL CPU @ 2.50GHZ
- GNU/Linux - 1 CPU - 2 virtual CPU - 4.06G RAM
Additional context tigase.log
Thank you for detailed description and analysis. We will investigate it further.
(ref: #server-1343)