From 4c7989e7e4c95ccfbdc189abc5bdea9aa9e90b02 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 7 May 2021 16:41:39 +0100 Subject: util.startup: Set more aggressive defaults for GC Testing has demonstrated that the default GC parameters are not sufficient to prevent runaway memory growth when running under Lua 5.2 and Lua 5.3. Setting the GC speed to 500 was tested on Lua versions 5.1->5.4 and did not display unbounded memory growth. --- util/startup.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/startup.lua b/util/startup.lua index c1f4ec8b..b3857830 100644 --- a/util/startup.lua +++ b/util/startup.lua @@ -12,7 +12,13 @@ local dependencies = require "util.dependencies"; local original_logging_config; -local default_gc_params = { mode = "incremental", threshold = 105, speed = 250 }; +local default_gc_params = { + mode = "incremental"; + -- Incremental mode defaults + threshold = 105, speed = 500; + -- Generational mode defaults + minor_threshold = 20, major_threshold = 50; +}; local short_params = { D = "daemonize", F = "no-daemonize" }; local value_params = { config = true }; -- cgit v1.2.3 From 06161ab7662dace66ac7f33198d6ded5683d5abe Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 10 May 2021 16:41:56 +0100 Subject: util.set: Add is_set() to test if an object is a set --- util/set.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/set.lua b/util/set.lua index 02fabc6a..b7345e7e 100644 --- a/util/set.lua +++ b/util/set.lua @@ -6,8 +6,8 @@ -- COPYING file in the source package for more information. -- -local ipairs, pairs, setmetatable, next, tostring = - ipairs, pairs, setmetatable, next, tostring; +local ipairs, pairs, getmetatable, setmetatable, next, tostring = + ipairs, pairs, getmetatable, setmetatable, next, tostring; local t_concat = table.concat; local _ENV = nil; @@ -31,6 +31,11 @@ function set_mt:__freeze() return a; end +local function is_set(o) + local mt = getmetatable(o); + return mt == set_mt; +end + local function new(list) local items = setmetatable({}, items_mt); local set = { _items = items }; @@ -171,6 +176,7 @@ end return { new = new; + is_set = is_set; union = union; difference = difference; intersection = intersection; -- cgit v1.2.3 From d126ee88bc666524339830b71141c92bb06cd283 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 10 May 2021 16:44:55 +0100 Subject: util.xmppstream: Reduce default xmppstream limit to 1MB --- util/xmppstream.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util') diff --git a/util/xmppstream.lua b/util/xmppstream.lua index 58cbd18e..e2c24c8a 100644 --- a/util/xmppstream.lua +++ b/util/xmppstream.lua @@ -22,7 +22,7 @@ local lxp_supports_doctype = pcall(lxp.new, { StartDoctypeDecl = false }); local lxp_supports_xmldecl = pcall(lxp.new, { XmlDecl = false }); local lxp_supports_bytecount = not not lxp.new({}).getcurrentbytecount; -local default_stanza_size_limit = 1024*1024*10; -- 10MB +local default_stanza_size_limit = 1024*1024*1; -- 1MB local _ENV = nil; -- luacheck: std none -- cgit v1.2.3 From 7cb3ec61d5117fa1be7077ea9efaef4d4e52ca57 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 10 May 2021 17:02:37 +0100 Subject: util.xmppstream: Mark bytes for stream closure as handled --- util/xmppstream.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'util') diff --git a/util/xmppstream.lua b/util/xmppstream.lua index e2c24c8a..57e1def3 100644 --- a/util/xmppstream.lua +++ b/util/xmppstream.lua @@ -188,6 +188,9 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress) stanza = t_remove(stack); end else + if lxp_supports_bytecount then + cb_handleprogress(stanza_size); + end if cb_streamclosed then cb_streamclosed(session); end -- cgit v1.2.3 From 92cec56e9760c6dc2dc3d775e81646e9995fc6b4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 10 May 2021 17:03:27 +0100 Subject: util.xmppstream: Allow dynamically configuring the stanza size limit for a stream This may be useful for any plugins that want to experiment with different policies for stanza size limits (e.g. unauthenticated vs authenticated streams). --- util/xmppstream.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'util') diff --git a/util/xmppstream.lua b/util/xmppstream.lua index 57e1def3..82a9820f 100644 --- a/util/xmppstream.lua +++ b/util/xmppstream.lua @@ -293,6 +293,9 @@ local function new(session, stream_callbacks, stanza_size_limit) return ok, err; end, set_session = meta.set_session; + set_stanza_size_limit = function (_, new_stanza_size_limit) + stanza_size_limit = new_stanza_size_limit; + end; }; end -- cgit v1.2.3