From c06cf5f1bf86fb12f909d48dbd796a37a2eb6251 Mon Sep 17 00:00:00 2001 From: Chris Mark Date: Thu, 21 May 2020 14:30:05 +0300 Subject: [PATCH] [Autodiscover] Check if runner is already running before starting again (#18564) (cherry picked from commit b0f7ae72161ef557f74838f5ac0aee1cdcba48f0) --- CHANGELOG.next.asciidoc | 2 ++ libbeat/cfgfile/list.go | 2 +- libbeat/cfgfile/list_test.go | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3996d4299c9..1b7a14e73dc 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -112,6 +112,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix panic when assigning a key to a `nil` value in an event. {pull}18143[18143] - Change `decode_json_fields` processor, to merge parsed json objects with existing objects in the event instead of fully replacing them. {pull}17958[17958] - Gives monitoring reporter hosts, if configured, total precedence over corresponding output hosts. {issue}17937[17937] {pull}17991[17991] +- [Autodiscover] Check if runner is already running before starting again. {pull}18564[18564] +- Fix `keystore add` hanging under Windows. {issue}18649[18649] {pull}18654[18654] *Auditbeat* diff --git a/libbeat/cfgfile/list.go b/libbeat/cfgfile/list.go index db02c56bbdd..1f3b2a7269b 100644 --- a/libbeat/cfgfile/list.go +++ b/libbeat/cfgfile/list.go @@ -70,7 +70,7 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error { continue } - if _, ok := stopList[hash]; ok { + if _, ok := r.runners[hash]; ok { delete(stopList, hash) } else { startList[hash] = config diff --git a/libbeat/cfgfile/list_test.go b/libbeat/cfgfile/list_test.go index 9d28187a503..3977efabaf0 100644 --- a/libbeat/cfgfile/list_test.go +++ b/libbeat/cfgfile/list_test.go @@ -103,6 +103,28 @@ func TestReloadSameConfigs(t *testing.T) { assert.Equal(t, state, list.copyRunnerList()) } +func TestReloadDuplicateConfig(t *testing.T) { + factory := &runnerFactory{} + list := NewRunnerList("", factory, nil) + + list.Reload([]*reload.ConfigWithMeta{ + createConfig(1), + }) + + state := list.copyRunnerList() + assert.Equal(t, len(state), 1) + + // This can happen in Autodiscover when a container if getting restarted + // but the previous one is not cleaned yet. + list.Reload([]*reload.ConfigWithMeta{ + createConfig(1), + createConfig(1), + }) + + // nothing changed + assert.Equal(t, state, list.copyRunnerList()) +} + func TestReloadStopConfigs(t *testing.T) { factory := &runnerFactory{} list := NewRunnerList("", factory, nil)