fix(core/etcd): nil-deref on response without header field#13361
Merged
Conversation
get_format() and other etcd wrapper functions access
res.body.header.revision without nil-guard. When the etcd response
body lacks a header field (e.g. proxy/LB injects its own JSON error,
or the upstream returns a non-etcd error), this raises:
attempt to index field 'header' (a nil value)
Add a get_header_revision() helper that returns nil,err when header or
revision is missing, and use it in all 6 call sites in etcd.lua.
Also guard config_etcd.lua watch init loop to retry instead of crash.
AlinsRan
approved these changes
May 12, 2026
shreemaan-abhishek
approved these changes
May 12, 2026
membphis
approved these changes
May 13, 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.
Several functions in
apisix/core/etcd.luaaccessres.body.header.revisionwithout checking whetherheaderexists. When the response body lacks an etcd v3headerfield — e.g. a reverse proxy returns its own JSON error, or the upstream returns a non-etcd response — this raisesattempt to index field 'header' (a nil value).Since
get_formatis called fromconfig_etcd.luaduringinit_worker_by_lua, a malformed response during bootstrap crashes the worker init phase entirely (CrashLoopBackoff in K8s deployments).This PR adds a
get_header_revision()helper that returnsnil, errwhenheaderorrevisionis missing, and uses it in all 6 affected call sites inetcd.lua. It also guards the directres.body.header.revisionaccess inconfig_etcd.lua's watch init retry loop to log and retry instead of crashing.