Skip to content

Commit c89e4a7

Browse files
committed
Start renewal job on random timer offset (ACME v2 rate limit)
This is to increase the chances that environments using multiple servers won't have all instances renewing at the same time, which might tie up all orders available to the account, and thus prevent certificates for new domains from being issued.
1 parent bc2a999 commit c89e4a7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/resty/auto-ssl/init_worker.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local random_seed = require "resty.auto-ssl.utils.random_seed"
22
local renewal_job = require "resty.auto-ssl.jobs.renewal"
33
local shell_blocking = require "shell-games"
44
local start_sockproc = require "resty.auto-ssl.utils.start_sockproc"
5+
local timer_rand = math.random()
56

67
return function(auto_ssl_instance)
78
local base_dir = auto_ssl_instance:get("dir")
@@ -37,5 +38,5 @@ return function(auto_ssl_instance)
3738
storage_adapter:setup_worker()
3839
end
3940

40-
renewal_job.spawn(auto_ssl_instance)
41+
renewal_job.spawn(auto_ssl_instance, timer_rand)
4142
end

lib/resty/auto-ssl/jobs/renewal.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ local function renew(premature, auto_ssl_instance)
270270
end
271271
end
272272

273-
function _M.spawn(auto_ssl_instance)
274-
local ok, err = ngx.timer.at(auto_ssl_instance:get("renew_check_interval"), renew, auto_ssl_instance)
273+
function _M.spawn(auto_ssl_instance, timer_rand)
274+
local ok, err = ngx.timer.at(timer_rand * auto_ssl_instance:get("renew_check_interval"), renew, auto_ssl_instance)
275275
if not ok then
276276
ngx.log(ngx.ERR, "auto-ssl: failed to create timer: ", err)
277277
return

0 commit comments

Comments
 (0)