aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-17 16:00:08 +0100
committerKim Alvefur <zash@zash.se>2021-12-17 16:00:08 +0100
commit685974b5d35f5429d4ea718fc94407b18044fb1f (patch)
treef6b2116e6317b8e4278c9bdfc0084d54dd6ee199
parentb5c32b6572869e71be6d53ca0e5f8014bf63e749 (diff)
downloadprosody-685974b5d35f5429d4ea718fc94407b18044fb1f.tar.gz
prosody-685974b5d35f5429d4ea718fc94407b18044fb1f.zip
mod_smacks: Preserve counter values on shutdown
-rw-r--r--plugins/mod_smacks.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/plugins/mod_smacks.lua b/plugins/mod_smacks.lua
index 18be51ce..8f8c827f 100644
--- a/plugins/mod_smacks.lua
+++ b/plugins/mod_smacks.lua
@@ -633,3 +633,25 @@ end
module:hook("s2s-read-timeout", handle_read_timeout);
module:hook("c2s-read-timeout", handle_read_timeout);
+
+module:hook_global("server-stopping", function()
+ -- Close smacks-enaled sessions ourselves instead of letting mod_c2s close
+ -- it, which invalidates the smacks session. This allows preserving the
+ -- counter value, so it can be communicated to the client when it tries to
+ -- resume the lost session after a restart.
+ for _, user in pairs(local_sessions) do
+ for _, session in pairs(user.sessions) do
+ if session.resumption_token then
+ if old_session_registry:set(session.username, session.resumption_token, { h = session.handled_stanza_count }) then
+ session.resumption_token = nil;
+ if session.conn then
+ session.conn:close()
+ session.conn = nil;
+ -- Now when mod_c2s gets here, it will immediately destroy the
+ -- session since it is unconnected.
+ end
+ end
+ end
+ end
+ end
+end, -90);