Skip to content

Commit

Permalink
fix(lock) do not call resty_lock.lock but use instance method (Kong#57)
Browse files Browse the repository at this point in the history
Renamed the lock for code clarity as well.
  • Loading branch information
Tieske authored and AlinsRan committed Jun 2, 2023
1 parent 45b37af commit bb5a3e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,16 @@ local function run_fn_locked_target_list(premature, self, fn)
return
end

local lock, lock_err = resty_lock:new(self.shm_name, {
local tl_lock, lock_err = resty_lock:new(self.shm_name, {
exptime = 10, -- timeout after which lock is released anyway
timeout = 5, -- max wait time to acquire lock
})

if not lock then
if not tl_lock then
return nil, "failed to create lock:" .. lock_err
end

local pok, perr = pcall(resty_lock.lock, lock, self.TARGET_LIST_LOCK)
local pok, perr = pcall(tl_lock.lock, tl_lock, self.TARGET_LIST_LOCK)
if not pok then
self:log(DEBUG, "failed to acquire lock: ", perr)
return nil, "failed to acquire lock"
Expand All @@ -299,7 +299,7 @@ local function run_fn_locked_target_list(premature, self, fn)
end

local ok
ok, err = lock:unlock()
ok, err = tl_lock:unlock()
if not ok then
-- recoverable: not returning this error, only logging it
self:log(ERR, "failed to release lock '", self.TARGET_LIST_LOCK,
Expand Down Expand Up @@ -535,24 +535,24 @@ local function run_mutexed_fn(premature, self, ip, port, hostname, fn)
return
end

local lock, lock_err = resty_lock:new(self.shm_name, {
local tlock, lock_err = resty_lock:new(self.shm_name, {
exptime = 10, -- timeout after which lock is released anyway
timeout = 5, -- max wait time to acquire lock
})
if not lock then
if not tlock then
return nil, "failed to create lock:" .. lock_err
end
local lock_key = key_for(self.TARGET_LOCK, ip, port, hostname)

local pok, perr = pcall(resty_lock.lock, lock, lock_key)
local pok, perr = pcall(tlock.lock, tlock, lock_key)
if not pok then
self:log(DEBUG, "failed to acquire lock: ", perr)
return nil, "failed to acquire lock"
end

local final_ok, final_err = pcall(fn)

local ok, err = lock:unlock()
local ok, err = tlock:unlock()
if not ok then
-- recoverable: not returning this error, only logging it
self:log(ERR, "failed to release lock '", lock_key, "': ", err)
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)
skips [#59](https://github.com/Kong/lua-resty-healthcheck/pull/59)
* fix: do not run out of timers during init/init_worker when adding a vast
amount of targets [#57](https://github.com/Kong/lua-resty-healthcheck/pull/57)
* fix: do not call on the module table, but use a method for locks. Also in
[#57](https://github.com/Kong/lua-resty-healthcheck/pull/57)

### 1.3.0 (17-Jun-2020)

Expand Down

0 comments on commit bb5a3e1

Please sign in to comment.