From 0f685e050135aacaa41a344f59fb228dc2b7b61b Mon Sep 17 00:00:00 2001 From: yiyiyimu Date: Tue, 20 Jul 2021 21:50:26 -0400 Subject: [PATCH 1/3] test: fix logic of retry in health check Signed-off-by: yiyiyimu --- lib/resty/etcd/v3.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/resty/etcd/v3.lua b/lib/resty/etcd/v3.lua index 437050eb..bcfebe24 100644 --- a/lib/resty/etcd/v3.lua +++ b/lib/resty/etcd/v3.lua @@ -142,9 +142,9 @@ local function _request_uri(self, method, uri, opts, timeout, ignore_auth) end else local max_retry = #self.endpoints * health_check.conf.max_fails + 1 - for _ = 1, max_retry do + for i = 1, max_retry do res, err = http_request_uri(self, http_cli, method, uri, body, headers, keepalive) - if err then + if not res then if err == "has no healthy etcd endpoint available" then return nil, err end @@ -152,6 +152,9 @@ local function _request_uri(self, method, uri, opts, timeout, ignore_auth) else break end + if i == max_retry then + return nil, "etcd request failed" + end end end From 4b138c3eb07603e42ffcc282fdd9c2351c70a2c9 Mon Sep 17 00:00:00 2001 From: yiyiyimu Date: Tue, 20 Jul 2021 21:52:48 -0400 Subject: [PATCH 2/3] update error returned Signed-off-by: yiyiyimu --- lib/resty/etcd/v3.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resty/etcd/v3.lua b/lib/resty/etcd/v3.lua index bcfebe24..b914f0d8 100644 --- a/lib/resty/etcd/v3.lua +++ b/lib/resty/etcd/v3.lua @@ -153,7 +153,7 @@ local function _request_uri(self, method, uri, opts, timeout, ignore_auth) break end if i == max_retry then - return nil, "etcd request failed" + return nil, err or "request etcd failed" end end end From 6d6d76061ce241f7f0927ea7b72cebbb10cda257 Mon Sep 17 00:00:00 2001 From: yiyiyimu Date: Tue, 20 Jul 2021 23:22:14 -0400 Subject: [PATCH 3/3] check if res is nil Signed-off-by: yiyiyimu --- lib/resty/etcd/v3.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/resty/etcd/v3.lua b/lib/resty/etcd/v3.lua index b914f0d8..9d3c2fd8 100644 --- a/lib/resty/etcd/v3.lua +++ b/lib/resty/etcd/v3.lua @@ -144,7 +144,7 @@ local function _request_uri(self, method, uri, opts, timeout, ignore_auth) local max_retry = #self.endpoints * health_check.conf.max_fails + 1 for i = 1, max_retry do res, err = http_request_uri(self, http_cli, method, uri, body, headers, keepalive) - if not res then + if err then if err == "has no healthy etcd endpoint available" then return nil, err end @@ -153,11 +153,15 @@ local function _request_uri(self, method, uri, opts, timeout, ignore_auth) break end if i == max_retry then - return nil, err or "request etcd failed" + return nil, err end end end + if not res then + return nil, "request etcd get nil response" + end + if not typeof.string(res.body) then return res end