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') 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 a7cc31c6bb735536d07b5578fbd3ed3ac3ba01ec Mon Sep 17 00:00:00 2001 From: tmolitor Date: Thu, 18 Mar 2021 14:30:47 +0100 Subject: mod_saslauth: Don't throw errors in async code when connections are gone Fixes #1515 --- plugins/mod_saslauth.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins') diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index e8bca7c3..e4888b01 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -44,6 +44,7 @@ local function build_reply(status, ret, err_msg) end local function handle_status(session, status, ret, err_msg) + if session["sasl_handler"] == nil then return "failure", "connection-timeout", "Connection gone"; end if status == "failure" then module:fire_event("authentication-failure", { session = session, condition = ret, text = err_msg }); session.sasl_handler = session.sasl_handler:clean_clone(); -- 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') 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') 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') 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 From 139cafdbafd73bd2d3359cda4bba2d389a8c87e1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Mar 2021 16:17:45 +0100 Subject: mod_saslauth: Improve code style This many returns deserve their own line. `session["sasl_handler"]` style isn't used anywhere else. --- plugins/mod_saslauth.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index e4888b01..5ba53f21 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -44,7 +44,9 @@ local function build_reply(status, ret, err_msg) end local function handle_status(session, status, ret, err_msg) - if session["sasl_handler"] == nil then return "failure", "connection-timeout", "Connection gone"; end + if not session.sasl_handler then + return "failure", "connection-timeout", "Connection gone"; + end if status == "failure" then module:fire_event("authentication-failure", { session = session, condition = ret, text = err_msg }); session.sasl_handler = session.sasl_handler:clean_clone(); -- cgit v1.2.3 From f1550b900d4095dfde87ccc60bbfebb088b03ef5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Mar 2021 16:16:54 +0100 Subject: mod_saslauth: Use a defined SASL error --- plugins/mod_saslauth.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 5ba53f21..6cd69f82 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -45,7 +45,7 @@ end local function handle_status(session, status, ret, err_msg) if not session.sasl_handler then - return "failure", "connection-timeout", "Connection gone"; + return "failure", "temporary-auth-failure", "Connection gone"; end if status == "failure" then module:fire_event("authentication-failure", { session = session, condition = ret, text = err_msg }); -- cgit v1.2.3