Changeset

8682:151ecd18d624

prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
author Matthew Wild <mwild1@gmail.com>
date Fri, 23 Mar 2018 14:18:27 +0000
parents 8681:0c077800cd70
children 8683:867ac771fb6e
files prosody util/startup.lua
diffstat 2 files changed, 28 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/prosody	Fri Mar 23 14:02:33 2018 +0000
+++ b/prosody	Fri Mar 23 14:18:27 2018 +0000
@@ -50,8 +50,13 @@
 end
 
 local startup = require "util.startup";
+local async = require "util.async";
 
-startup.prosody();
+-- Note: it's important that this thread is not GC'd, as some C libraries
+-- that are initialized here store a pointer to it ( :/ ).
+local thread = async.runner();
+
+thread:run(startup.prosody);
 
 local function loop()
 	-- Error handler for errors that make it this far
@@ -88,4 +93,4 @@
 prosody.events.fire_event("server-stopped");
 log("info", "Shutdown complete");
 
-os.exit(prosody.shutdown_code)
+os.exit(prosody.shutdown_code);
--- a/util/startup.lua	Fri Mar 23 14:02:33 2018 +0000
+++ b/util/startup.lua	Fri Mar 23 14:18:27 2018 +0000
@@ -5,7 +5,6 @@
 local prosody = { events = require "util.events".new() };
 
 local config = require "core.configmanager";
-local async = require "util.async";
 
 local dependencies = require "util.dependencies";
 
@@ -501,29 +500,27 @@
 end
 
 function startup.prosody()
-	async.once(function ()
-		-- These actions are in a strict order, as many depend on
-		-- previous steps to have already been performed
-		startup.read_config();
-		startup.sanity_check();
-		startup.sandbox_require();
-		startup.set_function_metatable();
-		startup.check_dependencies();
-		startup.load_libraries();
-		startup.init_global_state();
-		startup.init_logging();
-		startup.chdir();
-		startup.add_global_prosody_functions();
-		startup.read_version();
-		startup.log_greeting();
-		startup.log_dependency_warnings();
-		startup.load_secondary_libraries();
-		startup.init_http_client();
-		startup.init_data_store();
-		startup.init_global_protection();
-		startup.prepare_to_start();
-		startup.notify_started();
-	end);
+	-- These actions are in a strict order, as many depend on
+	-- previous steps to have already been performed
+	startup.read_config();
+	startup.sanity_check();
+	startup.sandbox_require();
+	startup.set_function_metatable();
+	startup.check_dependencies();
+	startup.load_libraries();
+	startup.init_global_state();
+	startup.init_logging();
+	startup.chdir();
+	startup.add_global_prosody_functions();
+	startup.read_version();
+	startup.log_greeting();
+	startup.log_dependency_warnings();
+	startup.load_secondary_libraries();
+	startup.init_http_client();
+	startup.init_data_store();
+	startup.init_global_protection();
+	startup.prepare_to_start();
+	startup.notify_started();
 end
 
 return startup;