From f56aaf1ba149176fe65254960cba957843c4ca10 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 11 Feb 2022 21:36:53 +0100 Subject: mod_c2s,mod_s2s: Disable and close port listeners before closing sessions This ensures no new clients can start connecting during shutdown --- .luacheckrc | 1 + plugins/mod_c2s.lua | 7 +++++++ plugins/mod_s2s.lua | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/.luacheckrc b/.luacheckrc index e8f7f1a0..0c934d90 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -48,6 +48,7 @@ files["plugins/"] = { "module.saved_state", "module.global", "module.path", + "module.items", -- Module API "module.add_extension", diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index c9aae3bc..7c5c4182 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -423,6 +423,13 @@ end module:hook("c2s-read-timeout", keepalive, -1); module:hook("server-stopping", function(event) + -- Close ports + local pm = require "core.portmanager"; + for _, netservice in pairs(module.items["net-provider"]) do + pm.unregister_service(netservice.name, netservice); + end + + -- Close sessions local reason = event.reason; for _, session in pairs(sessions) do session:close{ condition = "system-shutdown", text = reason }; diff --git a/plugins/mod_s2s.lua b/plugins/mod_s2s.lua index 3710a967..1b40f782 100644 --- a/plugins/mod_s2s.lua +++ b/plugins/mod_s2s.lua @@ -958,6 +958,13 @@ end module:hook("s2s-check-certificate", check_auth_policy, -1); module:hook("server-stopping", function(event) + -- Close ports + local pm = require "core.portmanager"; + for _, netservice in pairs(module.items["net-provider"]) do + pm.unregister_service(netservice.name, netservice); + end + + -- Close sessions local reason = event.reason; for _, session in pairs(sessions) do session:close{ condition = "system-shutdown", text = reason }; -- cgit v1.2.3