fix: handle missing X-Etcd-Index header gracefully in config_etcd#13364
Merged
Conversation
Replace assert(rev > 0) with a nil/non-positive check that logs a warning and falls through to the existing rev==0 retry path. This prevents a fatal init worker crash when the header is missing (e.g. a reverse proxy strips non-standard headers).
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Makes config_etcd resilient when the etcd response lacks the X-Etcd-Index header by avoiding a fatal assert and falling back to the existing “rev==0” retry path.
Changes:
- Replace
assert(rev > 0)with a warning +rev = 0fallback when the header is missing/invalid. - Add a regression test that simulates a response without
X-Etcd-Indexand verifies it doesn’t crash init worker.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
apisix/core/config_etcd.lua |
Avoids fatal init-worker failure by treating missing/invalid X-Etcd-Index as a retriable condition. |
t/core/config_etcd.t |
Adds coverage for the missing-header scenario and asserts a warning is logged. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -- 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) |
shreemaan-abhishek
approved these changes
May 12, 2026
shreemaan-abhishek
left a comment
Contributor
There was a problem hiding this comment.
interesting edge case, how did you find this?
AlinsRan
approved these changes
May 13, 2026
membphis
approved these changes
May 13, 2026
wistefan
pushed a commit
to wistefan/apisix
that referenced
this pull request
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the etcd response is missing the
X-Etcd-Indexheader (e.g. a reverse proxy strips non-standard headers),tonumber(nil)returnsniland theassert(rev > 0)raises — killing the init worker phase with no retry.This replaces the assert with a nil/non-positive check that logs a warning and falls through to the existing
rev == 0retry path, which fetches the current revision directly from etcd.The fix makes a transient header anomaly recoverable instead of fatal.