Skip to content

Commit 9a4e190

Browse files
authored
fix(autossl) fallback to stale cache if storage is not accessible (#82)
Proposed in #80
1 parent c937714 commit 9a4e190

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/resty/acme/autossl.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ end
104104

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

109109
if data then
110110
return data, nil
@@ -142,6 +142,9 @@ local function get_certkey_parsed(domain, typ)
142142
-- fill in local cache
143143
if cache then
144144
certs_cache[typ]:set(domain, cache, CERTS_CACHE_TTL)
145+
elseif err_ret and data_staled then
146+
log(ngx_WARN, err_ret, ", serving staled cert for ", domain)
147+
return data_staled, nil
145148
else
146149
certs_cache[typ]:set(domain, null, CERTS_CACHE_NEG_TTL)
147150
end
@@ -269,7 +272,7 @@ function AUTOSSL.update_cert(data)
269272
AUTOSSL.storage:set(failure_count_key, count)
270273
local cooloff = AUTOSSL.config.failure_cooloff
271274
if failure_cooloff_callback then
272-
cooloff = failure_cooloff_callback(domain, count)
275+
cooloff = failure_cooloff_callback(data.domain, count)
273276
end
274277
local now = ngx.now()
275278
AUTOSSL.storage:add(failure_lock_key, now + cooloff, cooloff)

0 commit comments

Comments
 (0)