From 0a115e1db2e19d7ea8ee8f5fca91f6e4749ef770 Mon Sep 17 00:00:00 2001 From: zhoujie Date: Mon, 21 Sep 2020 03:14:23 +0800 Subject: [PATCH] fix(targetlist) avoid `self.targets` being nil due to async behaviour (#44) when two worker create `checker`, `worker-0` first created and add target success, then `worker-1` creating, when `worker-1` call `worker_events:poll()` in line 1408, raise crash. `self.targets` init with empty table avoid this. --- README.md | 1 + lib/resty/healthcheck.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d73895f..a72b5bed 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/) * feature: added a status version field [#54](https://github.com/Kong/lua-resty-healthcheck/pull/54) * feature: add headers for probe request [#54](https://github.com/Kong/lua-resty-healthcheck/pull/54) * fix: exit early when reloading during a probe [#47](https://github.com/Kong/lua-resty-healthcheck/pull/47) +* fix: prevent target-list from being nil, due to async behaviour [#44](https://github.com/Kong/lua-resty-healthcheck/pull/44) ### 1.3.0 (17-Jun-2020) diff --git a/lib/resty/healthcheck.lua b/lib/resty/healthcheck.lua index b49fbd0f..c64924a0 100644 --- a/lib/resty/healthcheck.lua +++ b/lib/resty/healthcheck.lua @@ -1398,7 +1398,7 @@ function _M.new(opts) end -- other properties - self.targets = nil -- list of targets, initially loaded, maintained by events + self.targets = {} -- list of targets, initially loaded, maintained by events self.events = nil -- hash table with supported events (prevent magic strings) self.stopping = true -- flag to indicate to timers to stop checking self.timer_count = 0 -- number of running timers