Skip to content

Commit

Permalink
fix(lock) do not call resty_lock.lock but use instance method (#57)
Browse files Browse the repository at this point in the history
Renamed the lock for code clarity as well.
  • Loading branch information
Tieske committed Sep 22, 2020
1 parent 3f63633 commit 5d5d4fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)
* change: added additional logging on posting events [#25](https://github.com/Kong/lua-resty-healthcheck/issues/25)
* 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
16 changes: 8 additions & 8 deletions lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,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 @@ -256,7 +256,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 @@ -498,24 +498,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

0 comments on commit 5d5d4fb

Please sign in to comment.