Skip to content

fix: handle missing X-Etcd-Index header gracefully in config_etcd#13364

Merged
nic-6443 merged 3 commits into
apache:masterfrom
nic-6443:fix/config-etcd-missing-header
May 13, 2026
Merged

fix: handle missing X-Etcd-Index header gracefully in config_etcd#13364
nic-6443 merged 3 commits into
apache:masterfrom
nic-6443:fix/config-etcd-missing-header

Conversation

@nic-6443

Copy link
Copy Markdown
Member

When the etcd response is missing the X-Etcd-Index header (e.g. a reverse proxy strips non-standard headers), tonumber(nil) returns nil and the assert(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 == 0 retry path, which fetches the current revision directly from etcd.

The fix makes a transient header anomaly recoverable instead of fatal.

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).
Copilot AI review requested due to automatic review settings May 12, 2026 09:33
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels May 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = 0 fallback when the header is missing/invalid.
  • Add a regression test that simulates a response without X-Etcd-Index and 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.

Comment thread t/core/config_etcd.t
Comment thread t/core/config_etcd.t
Comment thread apisix/core/config_etcd.lua
Comment thread t/core/config_etcd.t
-- 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@shreemaan-abhishek shreemaan-abhishek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting edge case, how did you find this?

@nic-6443
nic-6443 merged commit 503f9eb into apache:master May 13, 2026
22 checks passed
@nic-6443
nic-6443 deleted the fix/config-etcd-missing-header branch May 13, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants