From d07c2f20624f3282505a64627fd27a9f06473d99 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 29 May 2018 10:38:27 +0200 Subject: [PATCH] libbeat: Stop autodiscover runners in a goroutine (#7170) (#7186) Stopping runners can be a blocking operation, what can block the autodiscover event loop. Run it in a goroutine so events can continue being handled. (cherry picked from commit 500ab7c7c5d11f5a34b6c0ce7b3a023fb033d763) --- CHANGELOG.asciidoc | 1 + libbeat/autodiscover/autodiscover.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 7c14a775836..beaafe63ac1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -121,6 +121,7 @@ https://github.com/elastic/beats/compare/v6.2.3...v6.3.0[View commits] - Ensure Kubernetes labels/annotations don't break mapping {pull}6490[6490] - Ensure that the dashboard zip files can't contain files outside of the kibana directory. {pull}6921[6921] - Fix map overwrite panics by cloning shared structs before doing the update. {pull}6947[6947] +- Fix delays on autodiscovery events handling caused by blocking runner stops. {pull}7170[7170] *Auditbeat* diff --git a/libbeat/autodiscover/autodiscover.go b/libbeat/autodiscover/autodiscover.go index cd7b557168d..945e524157a 100644 --- a/libbeat/autodiscover/autodiscover.go +++ b/libbeat/autodiscover/autodiscover.go @@ -174,8 +174,12 @@ func (a *Autodiscover) handleStop(event bus.Event) { } if runner := a.runners.Get(hash); runner != nil { + // Stop can block, we run it asyncrhonously to avoid blocking + // the whole events loop. The runner hash is removed in any case + // so an equivalent configuration can be added again while this + // one stops, and a duplicated event don't try to stop it twice. logp.Info("Autodiscover stopping runner: %s", runner) - runner.Stop() + go runner.Stop() a.runners.Remove(hash) } else { logp.Debug(debugK, "Runner not found for stopping: %s", hash)