Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 586:f733e7599ed6
mod_smacks: Add logging to hibernation and session destruction (thanks darkrain)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 29 Jan 2012 20:34:14 +0000 |
| parents | 44b69c3d5351 |
| children | 322a14acd974 |
comparison
equal
deleted
inserted
replaced
| 585:ce2798a1bc56 | 586:f733e7599ed6 |
|---|---|
| 179 module:log("warn", "::%s", tostring(queue[i])); | 179 module:log("warn", "::%s", tostring(queue[i])); |
| 180 end | 180 end |
| 181 handle_unacked_stanzas(session); | 181 handle_unacked_stanzas(session); |
| 182 end | 182 end |
| 183 else | 183 else |
| 184 session.log("debug", "mod_smacks hibernating session for up to %d seconds", resume_timeout); | |
| 184 local hibernate_time = os_time(); -- Track the time we went into hibernation | 185 local hibernate_time = os_time(); -- Track the time we went into hibernation |
| 185 session.hibernating = hibernate_time; | 186 session.hibernating = hibernate_time; |
| 186 local resumption_token = session.resumption_token; | 187 local resumption_token = session.resumption_token; |
| 187 timer.add_task(resume_timeout, function () | 188 timer.add_task(resume_timeout, function () |
| 189 session.log("debug", "mod_smacks hibernation timeout reached..."); | |
| 188 -- We need to check the current resumption token for this resource | 190 -- We need to check the current resumption token for this resource |
| 189 -- matches the smacks session this timer is for in case it changed | 191 -- matches the smacks session this timer is for in case it changed |
| 190 -- (for example, the client may have bound a new resource and | 192 -- (for example, the client may have bound a new resource and |
| 191 -- started a new smacks session, or not be using smacks) | 193 -- started a new smacks session, or not be using smacks) |
| 192 local curr_session = hosts[session.host].sessions[session.username].sessions[session.resource]; | 194 local curr_session = hosts[session.host].sessions[session.username].sessions[session.resource]; |
| 193 if curr_session.resumption_token == resumption_token | 195 if curr_session.resumption_token == resumption_token |
| 194 -- Check the hibernate time still matches what we think it is, | 196 -- Check the hibernate time still matches what we think it is, |
| 195 -- otherwise the session resumed and re-hibernated. | 197 -- otherwise the session resumed and re-hibernated. |
| 196 and session.hibernating == hibernate_time then | 198 and session.hibernating == hibernate_time then |
| 199 session.log("debug", "Destroying session for hibernating too long"); | |
| 197 session_registry[session.resumption_token] = nil; | 200 session_registry[session.resumption_token] = nil; |
| 198 session.resumption_token = nil; | 201 session.resumption_token = nil; |
| 199 -- This recursion back into our destroy handler is to | 202 -- This recursion back into our destroy handler is to |
| 200 -- make sure we still handle any queued stanzas | 203 -- make sure we still handle any queued stanzas |
| 201 sessionmanager.destroy_session(session); | 204 sessionmanager.destroy_session(session); |
| 205 else | |
| 206 session.log("debug", "Session resumed before hibernation timeout, all is well") | |
| 202 end | 207 end |
| 203 end); | 208 end); |
| 204 return; -- Postpone destruction for now | 209 return; -- Postpone destruction for now |
| 205 end | 210 end |
| 206 | 211 |
