[8.19](backport #7688) fix: ignore missing .fleet-agents index on enrollment _refresh path - #7692
Merged
Merged
Conversation
…th (#7688) * fix: close enroll search refresh response body after reading error When the pre-enrollment _refresh call returns a non-2xx response, the body was closed before String() was called to format the error message, producing "error reading response body: http: read on closed response body" instead of the actual ES error. Defer the close so String() can read the body first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: ignore missing .fleet-agents index on enrollment _refresh On a fresh Serverless project .fleet-agents does not exist when the first enrollment attempt arrives. The pre-enrollment _refresh call introduced in #7662 returned HTTP 404, which caused failQueue to be called and every enrollment to fail permanently — a deadlock where the index is never created because enrollment always fails before the first write lands. Pass ignore_unavailable=true to the refresh request so a missing index is treated as a no-op (HTTP 200, zero shards). The first enrollment proceeds to the msearch, writes the agent document (ES auto-creates .fleet-agents-7 with the correct alias and mappings via the system index descriptor), and subsequent retries with the same enrollment_id deduplicate correctly. Also fix the body-close ordering introduced in #7662: Body.Close() was called before String() in the error path, hiding the real ES error behind "read on closed response body". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fixup: address review feedback — close refresh body immediately, add missing-index integration test, remove unneeded changelog Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> (cherry picked from commit 9ab9134)
mergify
Bot
requested review from
lorienhu and
macdewee
and removed request for
a team
August 26, 2026 16:34
8 tasks
Contributor
TL;DRThe Buildkite failure is an infrastructure/network fetch error in the benchmark-compare job, not a code regression from this PR. Immediate action is to retry the build; if it recurs, add retry/pinning for the Remediation
Investigation detailsRoot CauseThe failing step is
PR code changes are limited to enrollment refresh/search logic in:
Evidence
Verification
Follow-up
What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
ycombinator
approved these changes
Aug 27, 2026
Contributor
Author
|
Tick the box to add this pull request to the merge queue (same as
|
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.
What is the problem this PR solves?
Fleet Server PR #7662 introduced a pre-enrollment
_refreshcall on.fleet-agentsto make prior writes visible before the deduplication msearch inkQueueEnrollSearch. On a fresh Serverless project the index does not yet exist, so_refreshreturns HTTP 404. This causesfailQueueto be called and every enrollment attempt to fail permanently — a deadlock where the index is never created because enrollment always fails before the first write can land.Only enrollments that include
enrollment_idare affected (they are routed throughkQueueEnrollSearch). Horde always setsenrollment_id; Elastic Agent may also set it. Agents that omitenrollment_idbypass this path and can enroll successfully, but they do not unblock the deadlocked agents.Discovered while investigating why Horde project drones never come online in Serverless staging (elastic/horde#569). ECH drones were unaffected because the Horde k8s smoke test deploys its own older fleet-server binary that predates #7662.
How does this PR solve the problem?
Two fixes:
1. Pass
ignore_unavailable=trueto the refresh request.When
.fleet-agentsdoes not exist the refresh becomes a no-op (HTTP 200, zero shards) instead of a fatal 404. The first enrollment proceeds to the msearch, the agent document is written, and ES auto-creates.fleet-agents-7with the correct alias and mappings via its system index descriptor. Subsequent retries with the sameenrollment_idthen deduplicate correctly.2. Fix body-close ordering (also introduced in #7662).
refreshResp.Body.Close()was called beforerefreshResp.String()in the error path, causing every enrollment failure on this path to be reported as:instead of the actual ES error. Changed to
defer refreshResp.Body.Close().How to test this PR locally
.fleet-agentsindex).enrollment_idset..fleet-agents-7is created with the.fleet-agentsalias.enrollment_idreturnsErrEnrollDuplicate.Design Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues
_refreshcall)This is an automatic backport of pull request fix: ignore missing
.fleet-agentsindex on enrollment_refreshpath #7688 done by Mergify.