You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/10/12 02:14:53 UTC

[apisix] branch master updated: fix: filter nil plugin conf triggered by etcd dir init (#5204)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new ebd4286  fix: filter nil plugin conf triggered by etcd dir init (#5204)
ebd4286 is described below

commit ebd428625293999d6647ce2958456031f134a0ec
Author: tzssangglass <tz...@gmail.com>
AuthorDate: Tue Oct 12 10:14:25 2021 +0800

    fix: filter nil plugin conf triggered by etcd dir init (#5204)
---
 apisix/plugin.lua   | 13 ++++++++-----
 t/cli/test_admin.sh | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index dbcce7f..cee49bd 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -244,11 +244,14 @@ function _M.load(config)
         http_plugin_names = {}
         stream_plugin_names = {}
         local plugins_conf = config.value
-        for _, conf in ipairs(plugins_conf) do
-            if conf.stream then
-                core.table.insert(stream_plugin_names, conf.name)
-            else
-                core.table.insert(http_plugin_names, conf.name)
+        -- plugins_conf can be nil when another instance writes into etcd key "/apisix/plugins/"
+        if plugins_conf then
+            for _, conf in ipairs(plugins_conf) do
+                if conf.stream then
+                    core.table.insert(stream_plugin_names, conf.name)
+                else
+                    core.table.insert(http_plugin_names, conf.name)
+                end
             end
         end
     end
diff --git a/t/cli/test_admin.sh b/t/cli/test_admin.sh
index 2ec2f7c..ac691b1 100755
--- a/t/cli/test_admin.sh
+++ b/t/cli/test_admin.sh
@@ -208,3 +208,24 @@ if ! echo "$out" | grep "Admin API can only be used with etcd config_center"; th
 fi
 
 echo "passed: Admin API can only be used with etcd config_center"
+
+# disable Admin API and init plugins syncer
+echo '
+apisix:
+  enable_admin: false
+' > conf/config.yaml
+
+rm logs/error.log
+make init
+make run
+
+make init
+
+if grep -E "failed to fetch data from etcd" logs/error.log; then
+    echo "failed: should sync /apisix/plugins from etcd when disabling admin normal"
+    exit 1
+fi
+
+make stop
+
+echo "pass: sync /apisix/plugins from etcd when disabling admin successfully"