From bb5a3e102bfa9f47f631414f0d2abdb3ad7ecf23 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 22 Sep 2020 14:18:07 +0200 Subject: [PATCH] fix(lock) do not call resty_lock.lock but use instance method (#57) Renamed the lock for code clarity as well. --- lib/resty/healthcheck.lua | 16 ++++++++-------- readme.md | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/resty/healthcheck.lua b/lib/resty/healthcheck.lua index 1d7f7f22..0b7f1e37 100644 --- a/lib/resty/healthcheck.lua +++ b/lib/resty/healthcheck.lua @@ -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" @@ -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, @@ -535,16 +535,16 @@ 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" @@ -552,7 +552,7 @@ local function run_mutexed_fn(premature, self, ip, port, hostname, fn) 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) diff --git a/readme.md b/readme.md index 0419b6f0..89feb973 100644 --- a/readme.md +++ b/readme.md @@ -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)