Skip to content

[9.5](backport #51911) handle PreInit error case for runReady.Close#51929

Merged
leehinman merged 3 commits into
9.5from
mergify/bp/9.5/pr-51911
Jul 15, 2026
Merged

[9.5](backport #51911) handle PreInit error case for runReady.Close#51929
leehinman merged 3 commits into
9.5from
mergify/bp/9.5/pr-51911

Conversation

@mergify

@mergify mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Proposed commit message

WHAT

filebeat/beater: close runReady on Manager.PreInit failure

PR #51864 (commit 00068f7) reordered the defers in Filebeat.Run so that defer fb.runReady.Close() runs before the managerEarlyStop defer (correct LIFO ordering to avoid a 5-second wait when the manager's stop callback calls StopWithContext). However, both defers were placed after the b.Manager.PreInit() call. If PreInit returns an error, Run exits before either defer is registered, leaving runReady.ch permanently unclosed.

An unclosed runReady.ch means any subsequent call to StopWithContext (e.g. via a SIGINT-triggered Manager.Stop that invokes the beat stop callback) will wait the full 5-second timeout before proceeding, rather than returning immediately.

WHY

Restores the invariant from before #51864: runReady is closed regardless of how Run exits. The fix adds an explicit fb.runReady.Close() on the PreInit error return path, which is the one path the deferred close cannot reach. A new unit test TestRunClosesRunReadyOnPreInitFailure directly asserts the channel is closed after Run returns due to a PreInit error; confirmed to fail against the buggy code and pass with the fix.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None. This is an internal shutdown-sequencing fix. The only observable change is that Elastic Agent-managed Filebeat instances where PreInit fails will no longer incur a spurious 5-second delay during shutdown.

How to test this PR locally

go test ./filebeat/beater/ -run "TestRunClosesRunReadyOnPreInitFailure|TestStopWaitsForRunReady" -v -count=1 -race

Related issues

Use cases

Screenshots

Logs


This is an automatic backport of pull request #51911 done by [Mergify](https://mergify.com).

* handle PreInit error case for runReady.Close

* fix fmt issue

(cherry picked from commit 397822f)

# Conflicts:
#	filebeat/beater/stop_test.go
@mergify mergify Bot requested a review from a team as a code owner July 14, 2026 14:53
@mergify mergify Bot added backport conflicts There is a conflict in the backported pull request labels Jul 14, 2026
@mergify mergify Bot requested review from AndersonQ and belimawr and removed request for a team July 14, 2026 14:53
@mergify

mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 397822f has failed:

On branch mergify/bp/9.5/pr-51911
Your branch is up to date with 'origin/9.5'.

You are currently cherry-picking commit 397822f0b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   filebeat/beater/filebeat.go

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   filebeat/beater/stop_test.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

TL;DR

The Buildkite failure is a compile-time backport mismatch, not a transient CI issue. The PR adds fb.runReady.Close() to the 9.5 Filebeat.Run path, but this backport does not include the runReady field/stop-sequencing change that defines it.

Remediation

Investigation details

Root Cause

The failed job reports filebeat/beater/filebeat.go:314:6: fb.runReady undefined (type *Filebeat has no field or method runReady). The PR diff adds fb.runReady.Close() at filebeat/beater/filebeat.go:314, but the backport cherry-pick already reported a conflict with filebeat/beater/stop_test.go being "deleted by us". That indicates the runReady-related changes from the source PR were not cleanly carried into the 9.5 branch; this PR contains only the PreInit error-path reference plus a new test that also depends on runReady.

Evidence

Verification

  • The failure occurs during go vet ./..., before tests execute. No additional tests were run because the checked-out workspace is not the failing 9.5 backport revision.

What is this? | From workflow: PR Buildkite Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@mergify

mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b mergify/bp/9.5/pr-51911 upstream/mergify/bp/9.5/pr-51911
git merge upstream/9.5
git push upstream mergify/bp/9.5/pr-51911

@leehinman leehinman enabled auto-merge (squash) July 14, 2026 23:19
@leehinman leehinman merged commit 5f2c89c into 9.5 Jul 15, 2026
48 checks passed
@leehinman leehinman deleted the mergify/bp/9.5/pr-51911 branch July 15, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bugfix conflicts There is a conflict in the backported pull request skip-changelog Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant