This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: discard any pending incoming stanzas when the stream is stopped
This fixes an ugly corner case and a potential for SM counters going out of sync. If stanzas are in the incoming queue when the broker task of the StanzaStream gets terminated, they are put back into the incoming queue. However, if the stream was actually covered by stream management, this will cause incorrect counters in the following edge case: 1. Stanzas arrive and are put in the incoming queue 2. The broker is terminated (because the underlying TCP stream gets killed, for instance, and on_closing of the xmlstream emits, which causes stop() to be called). 3. The incoming queue now has >0 elements, and the SM counter is set to the last element processed, *not including the incoming queue*. 4. The stream is re-established and SM is resumed. Based on the previous counter value, the server will now re-send all stanzas still in the incoming queue. 5. The broker task starts processing inbound stanzas, starting with those still in the incoming queue from the initial termination of the stream. Those have *also* been re-sent by definition by the server, so we'll now see, process and count those stanzas twice, causing incorrect stream management counters. This is not a common case during normal operations; typically, when an SM stream gets interrupted, it is due to a network going down or somesuch, which gives the broker task plenty of time to clear its inbound queue before it gets terminated.
- Loading branch information