Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 3646:58047d6f2b89
mod_smacks: fix bug #1405 (prevent timer from running for already destroyed sessions)
| author | tmolitor <thilo@eightysoft.de> |
|---|---|
| date | Sun, 11 Aug 2019 02:58:56 +0200 |
| parents | b2f32b3c6ec1 |
| children | b5d367798570 |
comparison
equal
deleted
inserted
replaced
| 3645:413ea67597d2 | 3646:58047d6f2b89 |
|---|---|
| 3 -- Copyright (C) 2010-2015 Matthew Wild | 3 -- Copyright (C) 2010-2015 Matthew Wild |
| 4 -- Copyright (C) 2010 Waqas Hussain | 4 -- Copyright (C) 2010 Waqas Hussain |
| 5 -- Copyright (C) 2012-2015 Kim Alvefur | 5 -- Copyright (C) 2012-2015 Kim Alvefur |
| 6 -- Copyright (C) 2012 Thijs Alkemade | 6 -- Copyright (C) 2012 Thijs Alkemade |
| 7 -- Copyright (C) 2014 Florian Zeitz | 7 -- Copyright (C) 2014 Florian Zeitz |
| 8 -- Copyright (C) 2016-2017 Thilo Molitor | 8 -- Copyright (C) 2016-2019 Thilo Molitor |
| 9 -- | 9 -- |
| 10 -- This project is MIT/X11 licensed. Please see the | 10 -- This project is MIT/X11 licensed. Please see the |
| 11 -- COPYING file in the source package for more information. | 11 -- COPYING file in the source package for more information. |
| 12 -- | 12 -- |
| 13 | 13 |
| 114 timer; | 114 timer; |
| 115 }; | 115 }; |
| 116 end | 116 end |
| 117 | 117 |
| 118 local function delayed_ack_function(session) | 118 local function delayed_ack_function(session) |
| 119 -- fire event only if configured to do so and our session is not hibernated or destroyed | 119 -- fire event only if configured to do so and our session is not already hibernated or destroyed |
| 120 if delayed_ack_timeout > 0 and session.awaiting_ack | 120 if delayed_ack_timeout > 0 and session.awaiting_ack |
| 121 and not session.hibernating and not session.destroyed then | 121 and not session.hibernating and not session.destroyed then |
| 122 session.log("debug", "Firing event 'smacks-ack-delayed', queue = %d", | 122 session.log("debug", "Firing event 'smacks-ack-delayed', queue = %d", |
| 123 session.outgoing_stanza_queue and #session.outgoing_stanza_queue or 0); | 123 session.outgoing_stanza_queue and #session.outgoing_stanza_queue or 0); |
| 124 module:fire_event("smacks-ack-delayed", {origin = session, queue = session.outgoing_stanza_queue}); | 124 module:fire_event("smacks-ack-delayed", {origin = session, queue = session.outgoing_stanza_queue}); |
| 169 if (#queue > max_unacked_stanzas and expected_h ~= session.last_requested_h) or force then | 169 if (#queue > max_unacked_stanzas and expected_h ~= session.last_requested_h) or force then |
| 170 session.log("debug", "Queuing <r> (in a moment) from %s - #queue=%d", reason, #queue); | 170 session.log("debug", "Queuing <r> (in a moment) from %s - #queue=%d", reason, #queue); |
| 171 session.awaiting_ack = false; | 171 session.awaiting_ack = false; |
| 172 session.awaiting_ack_timer = stoppable_timer(1e-06, function () | 172 session.awaiting_ack_timer = stoppable_timer(1e-06, function () |
| 173 -- session.log("debug", "*** SMACKS(3) ***: awaiting_ack=%s, hibernating=%s", tostring(session.awaiting_ack), tostring(session.hibernating)); | 173 -- session.log("debug", "*** SMACKS(3) ***: awaiting_ack=%s, hibernating=%s", tostring(session.awaiting_ack), tostring(session.hibernating)); |
| 174 if not session.awaiting_ack and not session.hibernating then | 174 -- only request ack if needed and our session is not already hibernated or destroyed |
| 175 if not session.awaiting_ack and not session.hibernating and not session.destroyed then | |
| 175 session.log("debug", "Sending <r> (inside timer, before send) from %s - #queue=%d", reason, #queue); | 176 session.log("debug", "Sending <r> (inside timer, before send) from %s - #queue=%d", reason, #queue); |
| 176 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) | 177 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) |
| 177 session.awaiting_ack = true; | 178 session.awaiting_ack = true; |
| 178 -- expected_h could be lower than this expression e.g. more stanzas added to the queue meanwhile) | 179 -- expected_h could be lower than this expression e.g. more stanzas added to the queue meanwhile) |
| 179 session.last_requested_h = session.last_acknowledged_stanza + #queue; | 180 session.last_requested_h = session.last_acknowledged_stanza + #queue; |
