comparison plugins/mod_s2s.lua @ 13957:8e6baa66f828

mod_s2s: Close outgoing pre-auth s2s sessions when their stanza queue is full
author Matthew Wild <mwild1@gmail.com>
date Thu, 25 Sep 2025 16:56:09 +0100
parents cbb8dc92daa9
children e3ef3e684855
comparison
equal deleted inserted replaced
13956:f50a9746fec0 13957:8e6baa66f828
198 if not host.sendq then 198 if not host.sendq then
199 -- luacheck: ignore 122 199 -- luacheck: ignore 122
200 host.sendq = queue.new(sendq_size); 200 host.sendq = queue.new(sendq_size);
201 end 201 end
202 if not host.sendq:push(st.clone(stanza)) then 202 if not host.sendq:push(st.clone(stanza)) then
203 host.log("warn", "stanza [%s] not queued ", stanza.name); 203 -- We shouldn't get here, because the last stanza
204 event.origin.send(st.error_reply(stanza, "wait", "resource-constraint", "Outgoing stanza queue full")); 204 -- should have triggered the 'full?' check.
205 return true; 205 host.log("warn", "Pending connection %s->%s has full queue - unable to queue %s stanza", from_host, to_host, stanza.name);
206 end 206 return false;
207 host.log("debug", "stanza [%s] queued ", stanza.name); 207 else
208 host.log("debug", "stanza [%s] queued ", stanza.name);
209 end
210
211 if host.sendq:full() then
212 -- A pending connection with a full queue could indicate
213 -- a stalled connection (trouble authenticating, etc.).
214 -- Our choice is to keep it open, and discard any additional stanzas
215 -- (which could cause inconsistencies, e.g. in MUC joins) or
216 -- force-close the connection.
217 host.log("warn", "Pending connection %s->%s has full queue - closing connection and bouncing stanzas", from_host, to_host);
218 host:close({
219 condition = "resource-constraint",
220 text = "Too many pending stanzas for this connection",
221 }, nil, "Too many pending stanzas for this connection");
222 end
223
224 -- Although in some cases the stanza was not delivered, it
225 -- was processed (queued or bounced), so we return true
208 return true; 226 return true;
209 elseif host.type == "local" or host.type == "component" then 227 elseif host.type == "local" or host.type == "component" then
210 log("error", "Trying to send a stanza to ourselves??") 228 log("error", "Trying to send a stanza to ourselves??")
211 log("error", "Traceback: %s", traceback()); 229 log("error", "Traceback: %s", traceback());
212 log("error", "Stanza: %s", stanza); 230 log("error", "Stanza: %s", stanza);