You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/09/28 03:19:33 UTC

[GitHub] [apisix] membphis commented on a change in pull request #2312: bugfix: create etcd object in `xpcall`, this step may fail

membphis commented on a change in pull request #2312:
URL: https://github.com/apache/apisix/pull/2312#discussion_r495669723



##########
File path: apisix/core/config_etcd.lua
##########
@@ -416,16 +416,20 @@ local function _automatic_fetch(premature, self)
         return
     end
 
-    local etcd_cli, _, err = etcd.new(self.etcd_conf)
-    if not etcd_cli then
-        error("failed to start a etcd instance: " .. err)
-    end
-    self.etcd_cli = etcd_cli
-
     local i = 0
     while not exiting() and self.running and i <= 32 do
         i = i + 1
+
         local ok, err = xpcall(function()
+            if not self.etcd_cli then
+                local etcd_cli, err = etcd.new(self.etcd_conf)
+                if not etcd_cli then
+                    error("failed to create etcd instance for key ["
+                          .. self.key .. "]: " .. (err or "unknown"))
+                end
+                self.etcd_cli = etcd_cli
+            end
+

Review comment:
       the old code is wrong. the return value is `res, err` for latest version of `resty-etcd`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org