Comparison

plugins/mod_smacks.lua @ 12043:48f8fa6cea7b

mod_smacks: Back out a86ae74da96c: Fixed one problem, caused another As per a86ae74da96c the 'session' object here is the wrong session, so the attempt to block stanzas from being added to the queue twice did not work causing something of a leak. Instead we have a leak of the previous session.
author Kim Alvefur <zash@zash.se>
date Mon, 13 Dec 2021 21:17:54 +0100
parent 12042:fe643b3a41f2
child 12044:9eb1a178293e
comparison
equal deleted inserted replaced
12042:fe643b3a41f2 12043:48f8fa6cea7b
196 local function outgoing_stanza_filter(stanza, session) 196 local function outgoing_stanza_filter(stanza, session)
197 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's 197 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's
198 -- supposed to be nil. 198 -- supposed to be nil.
199 -- However, when using mod_smacks with mod_websocket, then mod_websocket's 199 -- However, when using mod_smacks with mod_websocket, then mod_websocket's
200 -- stanzas/out filter can get called before this one and adds the xmlns. 200 -- stanzas/out filter can get called before this one and adds the xmlns.
201 if session.resending_unacked then return stanza end
202 local is_stanza = st.is_stanza(stanza) and 201 local is_stanza = st.is_stanza(stanza) and
203 (not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client') 202 (not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client')
204 and not stanza.name:find":"; 203 and not stanza.name:find":";
205 204
206 if is_stanza then 205 if is_stanza and not stanza._cached then
207 local queue = session.outgoing_stanza_queue; 206 local queue = session.outgoing_stanza_queue;
208 local cached_stanza = st.clone(stanza); 207 local cached_stanza = st.clone(stanza);
208 cached_stanza._cached = true;
209 209
210 if cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then 210 if cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then
211 cached_stanza = cached_stanza:tag("delay", { 211 cached_stanza = cached_stanza:tag("delay", {
212 xmlns = xmlns_delay, 212 xmlns = xmlns_delay,
213 from = jid.bare(session.full_jid or session.host), 213 from = jid.bare(session.full_jid or session.host),
598 -- ...they are what is now left in the outgoing stanza queue 598 -- ...they are what is now left in the outgoing stanza queue
599 -- We have to use the send of "session" because we don't want to add our resent stanzas 599 -- We have to use the send of "session" because we don't want to add our resent stanzas
600 -- to the outgoing queue again 600 -- to the outgoing queue again
601 local queue = original_session.outgoing_stanza_queue; 601 local queue = original_session.outgoing_stanza_queue;
602 session.log("debug", "resending all unacked stanzas that are still queued after resume, #queue = %d", #queue); 602 session.log("debug", "resending all unacked stanzas that are still queued after resume, #queue = %d", #queue);
603 session.resending_unacked = true;
604 for i=1,#queue do 603 for i=1,#queue do
605 session.send(queue[i]); 604 session.send(queue[i]);
606 end 605 end
607 session.resending_unacked = nil;
608 session.log("debug", "all stanzas resent, now disabling send() in this migrated session, #queue = %d", #queue); 606 session.log("debug", "all stanzas resent, now disabling send() in this migrated session, #queue = %d", #queue);
609 function session.send(stanza) -- luacheck: ignore 432 607 function session.send(stanza) -- luacheck: ignore 432
610 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza)); 608 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza));
611 return false; 609 return false;
612 end 610 end