Changeset

13543:01d2abc3d17c 0.12

mod_smacks: Destroy timed out session in async context (fixes #1884) Prevents ASYNC-01 due to storage interactions in a timer. Also considered modifying mod_c2s to allow passing arbitrary closures into its runner thread but this seems like a big step away from the current code for just this module. Also considered creating a dedicated runner in mod_smacks, but ensuring continuity across module reloads might be tricky. We could further improve this in the next major version.
author Kim Alvefur <zash@zash.se>
date Sat, 02 Nov 2024 18:10:25 +0100
parents 13528:c228f1ffb7b3
children 13544:0aae6de9d323 13546:1a915c2e0fa4
files plugins/mod_smacks.lua
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_smacks.lua	Sun Sep 29 18:09:17 2024 -0700
+++ b/plugins/mod_smacks.lua	Sat Nov 02 18:10:25 2024 +0100
@@ -494,14 +494,16 @@
 			return
 		end
 
-		session.log("debug", "Destroying session for hibernating too long");
-		session_registry[jid.join(session.username, session.host, session.resumption_token)] = nil;
-		old_session_registry:set(session.username, session.resumption_token,
-			{ h = session.handled_stanza_count; t = os.time() });
-		session.resumption_token = nil;
-		session.resending_unacked = true; -- stop outgoing_stanza_filter from re-queueing anything anymore
-		sessionmanager.destroy_session(session, "Hibernating too long");
-		sessions_expired(1);
+		prosody.main_thread:run(function ()
+			session.log("debug", "Destroying session for hibernating too long");
+			session_registry[jid.join(session.username, session.host, session.resumption_token)] = nil;
+			old_session_registry:set(session.username, session.resumption_token,
+				{ h = session.handled_stanza_count; t = os.time() });
+			session.resumption_token = nil;
+			session.resending_unacked = true; -- stop outgoing_stanza_filter from re-queueing anything anymore
+			sessionmanager.destroy_session(session, "Hibernating too long");
+			sessions_expired(1);
+		end);
 	end);
 	if session.conn then
 		local conn = session.conn;