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 2022/12/14 07:47:29 UTC

[GitHub] [apisix] kingluo opened a new issue, #8520: bug: timer leak in request-id plugin when reloaded

kingluo opened a new issue, #8520:
URL: https://github.com/apache/apisix/issues/8520

   ### Current Behavior
   
   The timer created by this plugin is only destroyed when `snowflake_inited` is true.
   But on some conditions, i.e. `etcd_cli:keepalive(lease_id)`, `snowflake_inited` would be set to `nil` but keep the timer running,
   then plugin reload would cause a timer leak.
   
   ```lua
   function _M.init()
   ...
       if attr.snowflake.enable then
           if process.type() == "worker" then
               ngx.timer.at(0, snowflake_init)
           end
       end
   end
   
   function _M.destroy()
       if snowflake_inited then
           timers.unregister_timer("plugin#request-id")
       end
   end
   
   local function snowflake_init()
       if snowflake_inited == nil then
   ...
           data_machine = gen_data_machine(max_number)
           if data_machine == nil then
               return ""
           end
   
   ...
           snowflake_inited = true
       end
   end
   
   local function gen_data_machine(max_number)
       if data_machine == nil then
   ...
                   local handler = function()
   ...
                       local _, err4 = etcd_cli:keepalive(lease_id)
                       if err4 then
                           snowflake_inited = nil
                           data_machine = nil
                           core.log.error("snowflake data_machine: " .. id .." lease failed.")
                       end
                       start_at = now
                       core.log.info("snowflake data_machine: " .. id .." lease success.")
                   end
   
                   timers.register_timer("plugin#request-id", handler)
   ...
                   break
               end
           end
   
           if data_machine == nil then
               core.log.error("No data_machine is not available")
               return nil
           end
       end
       return data_machine
   end
   ```
   
   ### Expected Behavior
   
   _No response_
   
   ### Error Logs
   
   _No response_
   
   ### Steps to Reproduce
   
   curl http://127.0.0.1:9180/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT
   
   ### Environment
   
   - APISIX version (run `apisix version`): master branch
   - Operating system (run `uname -a`):
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

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


[GitHub] [apisix] spacewander closed issue #8520: bug: timer leak in request-id plugin when reloaded

Posted by GitBox <gi...@apache.org>.
spacewander closed issue #8520: bug: timer leak in request-id plugin when reloaded
URL: https://github.com/apache/apisix/issues/8520


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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