SkyeYoung commented on code in PR #12383:
URL: https://github.com/apache/apisix/pull/12383#discussion_r2215262792


##########
apisix/core/config_etcd.lua:
##########
@@ -1001,7 +1001,7 @@ function _M.new(key, opts)
         sync_times = 0,
         running = true,
         conf_version = 0,
-        values = nil,
+        values = {},

Review Comment:
   Without this modification, the following problems will be encountered:
   
   ```
   Failed test 't/core/config_etcd.t TEST 12: test route with special character 
"-" - pattern "[error]" should not match any line in error.log but matches line 
"2025/07/09 14:24:01 [error] 1169428#1169428: *26 [lua] exporter.lua:534: 
Failed to collect metrics: 
   
   /home/xxx/apisix/apisix/consumer.lua:77: attempt to get length of local 
'data_list' (a nil value), context: ngx.timer" (req 0)
   ```
   
   In practice, even in 
[init.lua](https://github.com/apache/apisix/pull/12383/files#diff-7439ffe94cc4bcad12066d5d83f6c1004b8e9b3ff5097b645fa7c700eb3b3743),
 placing the `plugin.init_prometheus()` after all `.init_worker`, the relevant 
values may still be `nil` as shown in the error above. Therefore, it is 
necessary to handle the `values` before initialization.
   
   ----
   
   After the discussion with yuansheng and bzp a few days ago, there are two 
ways to handle it, one is the current one, and the other is as follows:
   
   ```lua
   -- add between 
https://github.com/SkyeYoung/apisix/blob/7a06f5c2f7b74cf621a0c2ff6878e8aa0e4e99a7/apisix/core/config_etcd.lua#L1030-L1031
   else
     load_full_data(obj, { nodes: {}}, nil)
     self.need_reload = true
   -- ^ This is why not use this method, 
   -- there is a hidden variable in `load_full_data` that needs to be reset
   ```
   
   Without resetting this variable, the [etcd-sync.t#TEST 
5](https://github.com/apache/apisix/blob/4377d05491ae2af228d40e3900362371363a8f46/t/core/etcd-sync.t#L141-L160)
 will be failed. (The reason is that the subsequent execution of 
`load_full_data` is missing)
   
   Thanks for the help from @bzp2010 , I was lost in the code.



-- 
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-unsubscr...@apisix.apache.org

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

Reply via email to