From e5050e7619cb1e879a23c930e9c2099b2a77ec3b Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Thu, 24 May 2018 13:15:16 +0200 Subject: [PATCH] libbeat: Stop autodiscover runners in a goroutine 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. --- CHANGELOG.asciidoc | 1 + libbeat/autodiscover/autodiscover.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index fff97407427..a00bd0ac56f 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -63,6 +63,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff] - Fix error if lz4 compression is used with the kafka output. {pull}7025[7025] - Preserve the event when source matching fails in `add_docker_metadata`. {pull}7133[7133] - Negotiate Docker API version from our client instead of using a hardcoded one. {pull}7165[7165] +- 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 37f70160fb4..8cdf27fcaf7 100644 --- a/libbeat/autodiscover/autodiscover.go +++ b/libbeat/autodiscover/autodiscover.go @@ -177,8 +177,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)