# HG changeset patch # User Matthew Wild # Date 1776362153 -3600 # Node ID 041c7ff18f76cc1e004099a4e9a53985d9821fd4 # Parent 4087c5b600b127ca0d5c2d79035b5b3ccb3a777d mod_cloud_notify: Fix leaking iq response handlers by using send_iq() diff -r 4087c5b600b1 -r 041c7ff18f76 plugins/mod_cloud_notify.lua --- a/plugins/mod_cloud_notify.lua Thu Apr 16 18:54:56 2026 +0100 +++ b/plugins/mod_cloud_notify.lua Thu Apr 16 18:55:53 2026 +0100 @@ -74,8 +74,7 @@ -- Forward declarations, as both functions need to reference each other local handle_push_success, handle_push_error; -function handle_push_error(event) - local stanza = event.stanza; +function handle_push_error(stanza) local error_type, condition, error_text = stanza:get_error(); local node = id2node[stanza.attr.id]; local identifier = id2identifier[stanza.attr.id]; @@ -117,11 +116,6 @@ changed = true; user_push_services[push_identifier] = nil push_errors[push_identifier] = nil; - -- unhook iq handlers for this identifier (if possible) - module:unhook("iq-error/host/"..stanza.attr.id, handle_push_error); - module:unhook("iq-result/host/"..stanza.attr.id, handle_push_success); - id2node[stanza.attr.id] = nil; - id2identifier[stanza.attr.id] = nil; end elseif user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type == "wait" then module:log("debug", "Got error <%s:%s:%s> for identifier '%s': " @@ -141,8 +135,7 @@ return true; end -function handle_push_success(event) - local stanza = event.stanza; +function handle_push_success(stanza) local node = id2node[stanza.attr.id]; local identifier = id2identifier[stanza.attr.id]; if node == nil then return false; end -- unknown stanza? Ignore for now! @@ -153,11 +146,6 @@ if push_identifier == identifier then if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and push_errors[push_identifier] > 0 then push_errors[push_identifier] = 0; - -- unhook iq handlers for this identifier (if possible) - module:unhook("iq-error/host/"..stanza.attr.id, handle_push_error); - module:unhook("iq-result/host/"..stanza.attr.id, handle_push_success); - id2node[stanza.attr.id] = nil; - id2identifier[stanza.attr.id] = nil; module:log("debug", "Push succeeded, error count for identifier '%s' is now at %s again", push_identifier, tostring(push_errors[push_identifier]) ); @@ -257,14 +245,6 @@ end user_push_services[key] = nil; push_errors[key] = nil; - for stanza_id, identifier in pairs(id2identifier) do - if identifier == key then - module:unhook("iq-error/host/"..stanza_id, handle_push_error); - module:unhook("iq-result/host/"..stanza_id, handle_push_success); - id2node[stanza_id] = nil; - id2identifier[stanza_id] = nil; - end - end end end local ok = push_store:flush_to_disk(origin.username); @@ -413,11 +393,13 @@ if push_errors[push_identifier] == nil then push_errors[push_identifier] = 0; end - module:hook("iq-error/host/"..stanza_id, handle_push_error); - module:hook("iq-result/host/"..stanza_id, handle_push_success); id2node[stanza_id] = node; id2identifier[stanza_id] = push_identifier; - module:send(push_publish); + module:send_iq(push_publish):next(handle_push_success, handle_push_error):finally(function () + -- unhook iq handlers for this identifier (if possible) + id2node[stanza.attr.id] = nil; + id2identifier[stanza.attr.id] = nil; + end); pushes = pushes + 1; end end