mod_http_file_share: Insert pauses to avoid blocknig for long periods
authorKim Alvefur <zash@zash.se>
Wed, 27 Jan 2021 22:10:11 +0100
changeset 11333 2a431d3ad8f1
parent 11332 ceaa3cebf28b
child 11334 f2c9492e3d25
mod_http_file_share: Insert pauses to avoid blocknig for long periods Similar to the mod_mam cleanup job
plugins/mod_http_file_share.lua
--- a/plugins/mod_http_file_share.lua	Wed Jan 27 22:09:26 2021 +0100
+++ b/plugins/mod_http_file_share.lua	Wed Jan 27 22:10:11 2021 +0100
@@ -263,6 +263,12 @@
 	local async = require "util.async";
 	local ENOENT = require "util.pposix".ENOENT;
 
+	local function sleep(t)
+		local wait, done = async.waiter();
+		module:add_timer(t, done)
+		wait();
+	end
+
 	local reaper_task = async.runner(function(boundary_time)
 		local iter, total = assert(uploads:find(nil, {["end"] = boundary_time; total = true}));
 
@@ -280,9 +286,11 @@
 			obsolete_files:push(get_filename(slot_id));
 		end
 
+		sleep(0.1);
 		local n = 0;
 		obsolete_files:filter(function(filename)
 			n = n + 1;
+			if i % 100 == 0 then sleep(0.1); end
 			local deleted, err, errno = os.remove(filename);
 			if deleted or errno == ENOENT then
 				return false;