tigase / tigase-server

(M) Highly optimized, extremely modular and very flexible XMPP/Jabber server
https://tigase.net
GNU Affero General Public License v3.0
317 stars 106 forks source link

Undelivered stanzas are processed before stream closure commands #184

Open reksi opened 1 year ago

reksi commented 1 year ago

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;

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.

[2022-12-27 08:05:24:390] [FINEST ] [ in_20-sess-man ] SessionManager.processPacket() : Packet blocked by: message, packetfrom=c2s@internal/10.10.10.10_5222_192.168.255.255_61068, to=sess-man@internal, DATA=<message from="d6ce@mydomain.com/5964a0422a5b938a" to="6711@mydomain.com" 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

woj-tek commented 1 year ago

Thank you for detailed description and analysis. We will investigate it further.

(ref: #server-1343)