Skip to content

bug: plugin hot reloading does not take effect #4314

Description

@Firstsawyou

Issue description

After modifying the code of the plugin, after performing the following operations according to the plugins.md document, the hot loading of the apisix plugin did not take effect.

curl http://127.0.0.1:9080/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT

Environment

Bug report without environment information will be ignored or closed.

  • apisix version (cmd: apisix version): 2.6
  • OS (cmd: uname -a): Linux
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): nginx version: openresty/1.19.3.1
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API): 3.4.0
  • apisix-dashboard version, if have:
  • luarocks version, if the issue is about installation (cmd: luarocks --version): 3.4.0

Minimal test code / Steps to reproduce the issue

Bug report without steps to reproduce will be ignored or closed.

  1. Modify the limit-count plugin code (add a warning log)
--- a/apisix/plugins/limit-count.lua
+++ b/apisix/plugins/limit-count.lua
@@ -156,7 +156,7 @@ end
 
 function _M.access(conf, ctx)
-    core.log.info("ver: ", ctx.conf_version)
+    core.log.warn("ver: ", ctx.conf_version, "hello world, 123456")
     local lim, err = core.lrucache.plugin_ctx(lrucache, ctx, conf.policy, create_limit_obj, conf)
     if not lim then
  1. Create a route and bind the plugin
curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/get",
    "plugins": {
        "limit-count": {
            "count": 3,
            "time_window": 10,
            "rejected_code": 503,
            "key": "remote_addr"
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "httpbin.org:80": 1
        }
    }
}'
  1. Execute hot load request
curl http://127.0.0.1:9080/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT
  1. Request a test
curl http://127.0.0.1:9080/get -i
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 300
Connection: keep-alive
X-RateLimit-Limit: 3
X-RateLimit-Remaining: 2
  1. View the error.log log (no plugin log output)
2021/05/26 22:13:18 [warn] 939867#939867: *164198 [lua] init.lua:290: sync_local_conf_to_etcd(): sync local conf to etcd, context: ngx.timer
  1. When the following code is commented, the plugin hot loading will take effect
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 5b4337c..7be84ac 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -167,7 +167,7 @@ local function load(plugin_names)
     -- the same configure may be synchronized more than one
     if plugins_eq(local_plugins_hash, processed) then
         core.log.info("plugins not changed")
-        return true
+        -- return true
     end
 
     core.log.warn("new plugins: ", core.json.delay_encode(processed))

Repeat the above steps 3, 4, and 5, and the plug-in hot loading takes effect.

2021/05/26 22:13:18 [warn] 939867#939867: *164198 [lua] init.lua:290: sync_local_conf_to_etcd(): sync local conf to etcd, context: ngx.timer
2021/05/26 22:13:31 [warn] 939868#939868: *164687 [lua] limit-count.lua:159: phase_func(): ver: 11517hello world, 123456, client: 127.0.0.1, server: _, request: "GET /get HTTP/1.1", host: "127.0.0.1:9080"

What's the actual result? (including assertion message & call stack if applicable)

After the hot reload request is executed, the code of the modified plugin cannot take effect.

What's the expected result?

After the hot load request is executed, the modification of the plugin code can take effect in time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions