This is an automated email from the ASF dual-hosted git repository.
nic-6443 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 503f9eb7b fix: handle missing X-Etcd-Index header gracefully in
config_etcd (#13364)
503f9eb7b is described below
commit 503f9eb7bb49b854a1ff26c372a3dc0ce4c2643d
Author: Nic <[email protected]>
AuthorDate: Wed May 13 12:01:17 2026 +0800
fix: handle missing X-Etcd-Index header gracefully in config_etcd (#13364)
---
apisix/core/config_etcd.lua | 7 +++++--
t/core/config_etcd.t | 48 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua
index a91199edd..d5753c5e8 100644
--- a/apisix/core/config_etcd.lua
+++ b/apisix/core/config_etcd.lua
@@ -49,7 +49,6 @@ local string = string
local error = error
local pairs = pairs
local next = next
-local assert = assert
local rand = math.random
local constants = require("apisix.constants")
local health_check = require("resty.etcd.health_check")
@@ -150,7 +149,11 @@ local function do_run_watch(premature)
local _, res = next(loaded_configuration)
if res then
rev = tonumber(res.headers["X-Etcd-Index"])
- assert(rev > 0, 'invalid res.headers["X-Etcd-Index"]')
+ if not rev or rev <= 0 then
+ log.warn("invalid or missing X-Etcd-Index header, ",
+ "will fetch revision from etcd directly")
+ rev = 0
+ end
end
end
diff --git a/t/core/config_etcd.t b/t/core/config_etcd.t
index ead9112aa..9ccac862f 100644
--- a/t/core/config_etcd.t
+++ b/t/core/config_etcd.t
@@ -567,3 +567,51 @@ passed
qr/etcd watch timeout, upgrade revision to/
--- grep_error_log_out eval
qr/(etcd watch timeout, upgrade revision to\n){2,}/
+
+
+
+=== TEST 15: missing X-Etcd-Index header should not crash init worker
+--- yaml_config
+deployment:
+ role: traditional
+ role_traditional:
+ config_provider: etcd
+ etcd:
+ host:
+ - "http://127.0.0.1:2379"
+ prefix: /apisix
+--- extra_init_by_lua
+ -- Clear loaded_configuration and inject a fake entry with missing
+ -- X-Etcd-Index header so do_run_watch exercises the fallback path.
+ local config_etcd = require("apisix.core.config_etcd")
+ for i = 1, 256 do
+ local name, val = debug.getupvalue(config_etcd.new, i)
+ if not name then
+ break
+ end
+ if name == "loaded_configuration" and type(val) == "table" then
+ for k in pairs(val) do
+ val[k] = nil
+ end
+ val["__test_fake"] = {
+ body = { nodes = {} },
+ headers = {},
+ }
+ break
+ end
+ end
+--- config
+ location /t {
+ content_by_lua_block {
+ ngx.sleep(1)
+ ngx.say("passed")
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- grep_error_log eval
+qr/invalid or missing X-Etcd-Index header/
+--- grep_error_log_out eval
+qr/(invalid or missing X-Etcd-Index header\n){1,}/