Software /
code /
prosody
Changeset
11984:a86ae74da96c
mod_smacks: Avoid duplicated queueing using flag on session instead of stanza
Mutating the stanza like this is Really Bad Practice.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 02 Dec 2021 13:56:50 +0100 |
parents | 11983:27f2539b4f87 |
children | 11985:3740cf7a66a3 |
files | plugins/mod_smacks.lua |
diffstat | 1 files changed, 4 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_smacks.lua Thu Dec 02 13:49:42 2021 +0100 +++ b/plugins/mod_smacks.lua Thu Dec 02 13:56:50 2021 +0100 @@ -198,14 +198,14 @@ -- supposed to be nil. -- However, when using mod_smacks with mod_websocket, then mod_websocket's -- stanzas/out filter can get called before this one and adds the xmlns. + if session.resending_unacked then return stanza end local is_stanza = st.is_stanza(stanza) and (not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client') and not stanza.name:find":"; - if is_stanza and not stanza._cached then + if is_stanza then local queue = session.outgoing_stanza_queue; local cached_stanza = st.clone(stanza); - cached_stanza._cached = true; if cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then cached_stanza = cached_stanza:tag("delay", { @@ -611,9 +611,11 @@ -- to the outgoing queue again local queue = original_session.outgoing_stanza_queue; session.log("debug", "resending all unacked stanzas that are still queued after resume, #queue = %d", #queue); + session.resending_unacked = true; for i=1,#queue do session.send(queue[i]); end + session.resending_unacked = nil; session.log("debug", "all stanzas resent, now disabling send() in this migrated session, #queue = %d", #queue); function session.send(stanza) -- luacheck: ignore 432 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza));