Skip to content

Commit 4cd8cc1

Browse files
authored
Merge pull request #76 from GUI/sockproc-lock-race
Fix sockproc startup race conditions after running out of memory
2 parents ad1c3df + e26eff6 commit 4cd8cc1

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ local function do_renew(auto_ssl_instance)
133133
if not get_interval_lock("renew", auto_ssl_instance:get("renew_check_interval")) then
134134
return
135135
end
136-
local renew_lock, new_renew_lock_err = lock:new("auto_ssl", { exptime = 1800, timeout = 0 })
136+
local renew_lock, new_renew_lock_err = lock:new("auto_ssl_settings", { exptime = 1800, timeout = 0 })
137137
if new_renew_lock_err then
138138
ngx.log(ngx.ERR, "auto-ssl: failed to create lock: ", new_renew_lock_err)
139139
return

lib/resty/auto-ssl/utils/shell_execute.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ return function(command)
1717
wait_time = wait_time + sleep_time
1818

1919
if wait_time > max_time then
20+
ngx.log(ngx.ERR, "auto-ssl: sockproc did not start in expected amount of time")
2021
break
2122
end
2223
end

lib/resty/auto-ssl/utils/start_sockproc.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ local auto_ssl = require "resty.auto-ssl"
22
local lock = require "resty.lock"
33

44
local function start()
5+
local _, set_false_err = ngx.shared.auto_ssl_settings:safe_set("sockproc_started", false)
6+
if set_false_err then
7+
ngx.log(ngx.ERR, "auto-ssl: failed to set shdict for sockproc_started: ", set_false_err)
8+
end
9+
510
ngx.log(ngx.NOTICE, "auto-ssl: starting sockproc")
11+
612
local exit_status = os.execute("umask 0022 && " .. auto_ssl.lua_root .. "/bin/resty-auto-ssl/start_sockproc")
713
-- Lua 5.2+ returns boolean. Prior versions return status code.
814
if exit_status == 0 or exit_status == true then
@@ -21,7 +27,7 @@ return function(force)
2127
end
2228

2329
-- Add lock to ensure only a single start command is attempted at a time.
24-
local start_lock, new_lock_err = lock:new("auto_ssl", { exptime = 600, timeout = 0 })
30+
local start_lock, new_lock_err = lock:new("auto_ssl_settings", { exptime = 600, timeout = 0 })
2531
if new_lock_err then
2632
ngx.log(ngx.ERR, "Failed to create lock: ", new_lock_err)
2733
return

0 commit comments

Comments
 (0)