mod_c2s,mod_s2s: Disable and close port listeners before closing sessions

This ensures no new clients can start connecting during shutdown
This commit is contained in:
Kim Alvefur 2022-02-11 21:36:53 +01:00
parent 89f110bbf2
commit f56aaf1ba1
3 changed files with 15 additions and 0 deletions

View file

@ -48,6 +48,7 @@ files["plugins/"] = {
"module.saved_state", "module.saved_state",
"module.global", "module.global",
"module.path", "module.path",
"module.items",
-- Module API -- Module API
"module.add_extension", "module.add_extension",

View file

@ -423,6 +423,13 @@ end
module:hook("c2s-read-timeout", keepalive, -1); module:hook("c2s-read-timeout", keepalive, -1);
module:hook("server-stopping", function(event) 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; local reason = event.reason;
for _, session in pairs(sessions) do for _, session in pairs(sessions) do
session:close{ condition = "system-shutdown", text = reason }; session:close{ condition = "system-shutdown", text = reason };

View file

@ -958,6 +958,13 @@ end
module:hook("s2s-check-certificate", check_auth_policy, -1); module:hook("s2s-check-certificate", check_auth_policy, -1);
module:hook("server-stopping", function(event) 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; local reason = event.reason;
for _, session in pairs(sessions) do for _, session in pairs(sessions) do
session:close{ condition = "system-shutdown", text = reason }; session:close{ condition = "system-shutdown", text = reason };