# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1683455275 -7200
# Node ID 1693bd4de283bd46f9e522e30d20eeafb162ebe4
# Parent  4002f0aa6a0455b527fcccdb8a9189ce02002f0f
core.sessionmanager: Delay closing a replaced connection after replacement

Closing the session invokes ondisconnect and session close logic,
including mod_smacks hibernation and the timer that destroys the session
after a timeout.

By closing the connection after it has been detached from the sessions
table it will no longer invoke the ondetach handler, which should
prevent the above problem.

diff -r 4002f0aa6a04 -r 1693bd4de283 core/sessionmanager.lua
--- a/core/sessionmanager.lua	Thu May 04 17:30:40 2023 +0200
+++ b/core/sessionmanager.lua	Sun May 07 12:27:55 2023 +0200
@@ -100,8 +100,7 @@
 
 	local replaced_conn = to_session.conn;
 	if replaced_conn then
-		to_session.log("debug", "closing a replaced connection for this session");
-		replaced_conn:close();
+		to_session.conn = nil;
 	end
 
 	to_session.since = from_session.since;
diff -r 4002f0aa6a04 -r 1693bd4de283 plugins/mod_c2s.lua
--- a/plugins/mod_c2s.lua	Thu May 04 17:30:40 2023 +0200
+++ b/plugins/mod_c2s.lua	Sun May 07 12:27:55 2023 +0200
@@ -273,6 +273,7 @@
 	local replaced_conn = event.replaced_conn;
 	if replaced_conn then
 		sessions[replaced_conn] = nil;
+		replaced_conn:close();
 	end
 end);