diff --git a/README.md b/README.md index bd947168..842220bd 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/) * fix: exit early when reloading during a probe [#47](https://github.com/Kong/lua-resty-healthcheck/pull/47) * 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) diff --git a/lib/resty/healthcheck.lua b/lib/resty/healthcheck.lua index 7567bb8b..6ce5e125 100644 --- a/lib/resty/healthcheck.lua +++ b/lib/resty/healthcheck.lua @@ -231,16 +231,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" @@ -257,7 +257,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, @@ -493,16 +493,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" @@ -510,7 +510,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)