comparison plugins/mod_smacks.lua @ 13576:5d8fc1c4eb7c

mod_smacks: Run session destruction code in session's async context This is the Right Thing and should fix various potential issues and race conditions.
author Matthew Wild <mwild1@gmail.com>
date Thu, 21 Nov 2024 17:02:55 +0000
parents 9277fc78fe39
children 5f8a9e50c2fb
comparison
equal deleted inserted replaced
13575:750ff9f579e2 13576:5d8fc1c4eb7c
539 -- This should normally not happen, the watchdog should be canceled from session:close() 539 -- This should normally not happen, the watchdog should be canceled from session:close()
540 session.log("debug", "The session has already been resumed or replaced"); 540 session.log("debug", "The session has already been resumed or replaced");
541 return 541 return
542 end 542 end
543 543
544 prosody.main_thread:run(function () 544 session.thread:run({
545 session.log("debug", "Destroying session for hibernating too long"); 545 event = "callback";
546 save_old_session(session); 546 name = "mod_smacks/destroy_hibernating";
547 session.resumption_token = nil; 547 callback = function ()
548 sessionmanager.destroy_session(session, "Hibernating too long"); 548 session.log("debug", "Destroying session for hibernating too long");
549 sessions_expired(1); 549 save_old_session(session);
550 end); 550 session.resumption_token = nil;
551 sessionmanager.destroy_session(session, "Hibernating too long");
552 sessions_expired(1);
553 end;
554 });
551 end); 555 end);
552 if session.conn then 556 if session.conn then
553 local conn = session.conn; 557 local conn = session.conn;
554 c2s_sessions[conn] = nil; 558 c2s_sessions[conn] = nil;
555 session.conn = nil; 559 session.conn = nil;