[8.19](backport #51864) managerEarlyStop before runReady close#51871
[8.19](backport #51864) managerEarlyStop before runReady close#51871mergify[bot] wants to merge 1 commit into
Conversation
(cherry picked from commit 00068f7) # Conflicts: # filebeat/beater/filebeat.go
|
Cherry-pick of 00068f7 has failed: 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 |
🤖 GitHub commentsJust comment with:
|
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
TL;DRThe Buildkite Remediation
Investigation detailsRoot CauseThe PR merge result includes conflict-marker lines in Evidence
Verification
What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
Proposed commit message
Fix defer ordering bug in Filebeat.Run that caused a 5-second hang on every early-exit error path.
WHAT: Move defer fb.runReady.Close() from the top of Run() to just after the managerEarlyStop defer.
Go defers execute in LIFO order. Previously defer fb.runReady.Close() was set up first (line 277), which meant it ran last — after managerEarlyStop(). managerEarlyStop() calls b.Manager.Stop(), which triggers the stop callback, which calls beater.Stop() → StopWithContext(context.Background()). That function blocks up to 5 seconds waiting for runReady.ch to be closed. But runReady.ch was only closed by the later defer, creating a deadlock that always timed out.
By deferring runReady.Close() after the managerEarlyStop defer, it now runs before it in LIFO order. When managerEarlyStop() calls Stop(), runReady.ch is already closed and Stop() returns immediately.
WHY: The system test test_stopping_empty_path configures a log input with paths: [], which causes crawler.Start() to fail and Run() to exit early. On this early-exit path managerEarlyStop is non-nil and gets called in its defer, triggering the 5-second hang before the error is logged. The test's 7-second window (2s sleep + 5s wait) was being exhausted before logp.Critical("Exiting: ...") was ever written to the log file.
Checklist
stresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Disruptive User Impact
None. This only affects the internal shutdown sequencing on error paths inside Run().
How to test this PR locally
go test ./filebeat/beater/... -run TestStop -vFor the full system test (requires a built filebeat binary):
Related issues
Use cases
Screenshots
Logs
This is an automatic backport of pull request #51864 done by [Mergify](https://mergify.com).