Skip to content

Commit

Permalink
fix(autossl) fallback to stale cache if storage is not accessible
Browse files Browse the repository at this point in the history
Proposed in #80
  • Loading branch information
fffonion committed Oct 20, 2022
1 parent 380e769 commit 6193fbe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/resty/acme/autossl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ end

-- get cert and key cdata with caching
local function get_certkey_parsed(domain, typ)
local data, _ --[[stale]], _ --[[flags]] = certs_cache[typ]:get(domain)
local data, data_staled, _ --[[flags]] = certs_cache[typ]:get(domain)

if data then
return data, nil
Expand Down Expand Up @@ -142,6 +142,9 @@ local function get_certkey_parsed(domain, typ)
-- fill in local cache
if cache then
certs_cache[typ]:set(domain, cache, CERTS_CACHE_TTL)
elseif err_ret and data_staled then
log(ngx_WARN, err_ret, ", serving staled cert for ", domain)
return data_staled, nil
else
certs_cache[typ]:set(domain, null, CERTS_CACHE_NEG_TTL)
end
Expand Down Expand Up @@ -269,7 +272,7 @@ function AUTOSSL.update_cert(data)
AUTOSSL.storage:set(failure_count_key, count)
local cooloff = AUTOSSL.config.failure_cooloff
if failure_cooloff_callback then
cooloff = failure_cooloff_callback(domain, count)
cooloff = failure_cooloff_callback(data.domain, count)
end
local now = ngx.now()
AUTOSSL.storage:add(failure_lock_key, now + cooloff, cooloff)
Expand Down

0 comments on commit 6193fbe

Please sign in to comment.