mod_http_oauth2: Periodically trim unused authorization codes
authorKim Alvefur <zash@zash.se>
Sun, 22 Nov 2020 19:11:42 +0100
changeset 4276 91b951fb3018
parent 4275 9623b99bb8d2
child 4277 8bf83e883593
mod_http_oauth2: Periodically trim unused authorization codes
mod_http_oauth2/mod_http_oauth2.lua
--- a/mod_http_oauth2/mod_http_oauth2.lua	Sun Nov 22 18:49:31 2020 +0100
+++ b/mod_http_oauth2/mod_http_oauth2.lua	Sun Nov 22 19:11:42 2020 +0100
@@ -22,6 +22,15 @@
 	return code_expired(code)
 end);
 
+module:add_timer(900, function()
+	local k, code = codes:tail();
+	while code and code_expired(code) do
+		codes:set(k, nil);
+		k, code = codes:tail();
+	end
+	return 900;
+end)
+
 local function oauth_error(err_name, err_desc)
 	return errors.new({
 		type = "modify";