From 2b0c472f871d404852dd50e97868165920a10f9b Mon Sep 17 00:00:00 2001 From: tmolitor Date: Thu, 18 Mar 2021 14:30:32 +0100 Subject: mod_c2s: Don't throw errors in async code when connections are gone Fixes #1507 --- plugins/mod_c2s.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/mod_c2s.lua') diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index c648850f..f8675258 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -226,11 +226,11 @@ module:hook_global("user-password-changed", function(event) end, 200); function runner_callbacks:ready() - self.data.conn:resume(); + if self.data["conn"] ~= nil then self.data.conn:resume(); end end function runner_callbacks:waiting() - self.data.conn:pause(); + if self.data["conn"] ~= nil then self.data.conn:pause(); end end function runner_callbacks:error(err) -- cgit v1.2.3 From b5f808c769e384bed666e92a221516f424f55fae Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Mar 2021 12:47:16 +0100 Subject: mod_c2s: Fix traceback in session close when conn is nil Unclear how this happens. --- plugins/mod_c2s.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/mod_c2s.lua') diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index f8675258..f3259ed2 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -190,12 +190,12 @@ local function session_close(session, reason) if not session.destroyed then session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); sm_destroy_session(session, reason_text); - conn:close(); + if conn then conn:close(); end end end); else sm_destroy_session(session, reason_text); - conn:close(); + if conn then conn:close(); end end else local reason_text = (reason and (reason.name or reason.text or reason.condition)) or reason; -- cgit v1.2.3 From 846862e1e703be347136f5e3fe81e4c958cb8635 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Mar 2021 16:23:47 +0100 Subject: mod_c2s: Improve code style We don't use the quoted table indexing style that often, it's not needed here and it's enough to check for falsyness rather than `nil`. --- plugins/mod_c2s.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'plugins/mod_c2s.lua') diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index f3259ed2..57b7b0f7 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -226,11 +226,15 @@ module:hook_global("user-password-changed", function(event) end, 200); function runner_callbacks:ready() - if self.data["conn"] ~= nil then self.data.conn:resume(); end + if self.data.conn then + self.data.conn:resume(); + end end function runner_callbacks:waiting() - if self.data["conn"] ~= nil then self.data.conn:pause(); end + if self.data.conn then + self.data.conn:pause(); + end end function runner_callbacks:error(err) -- cgit v1.2.3 From 72cb2e0362b195131334c3a2b1c20dbb5f7398c7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Mar 2021 16:24:46 +0100 Subject: mod_c2s: Log about missing conn on async state changes --- plugins/mod_c2s.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins/mod_c2s.lua') diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 57b7b0f7..8d4dcfb8 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -228,12 +228,16 @@ end, 200); function runner_callbacks:ready() if self.data.conn then self.data.conn:resume(); + else + (self.data.log or log)("debug", "Session has no connection to resume"); end end function runner_callbacks:waiting() if self.data.conn then self.data.conn:pause(); + else + (self.data.log or log)("debug", "Session has no connection to pause while waiting"); end end -- cgit v1.2.3