diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index dd230fb5a406..a6856b4c1c2c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -67,6 +67,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Add raw JSON to message field when JSON parsing fails. {issue}6516[6516] *Heartbeat* +- Fix race due to updates of shared a map, that was not supposed to be shared between multiple go-routines. {issue}6616[6616] *Metricbeat* diff --git a/heartbeat/monitors/util.go b/heartbeat/monitors/util.go index 88b58984e2ff..efd6c7551964 100644 --- a/heartbeat/monitors/util.go +++ b/heartbeat/monitors/util.go @@ -122,6 +122,8 @@ func annotated( } if fields != nil { + fields = fields.Clone() + status := look.Status(err) fields.DeepUpdate(common.MapStr{ "monitor": common.MapStr{ @@ -130,7 +132,7 @@ func annotated( }, }) if user := settings.Fields; user != nil { - fields.DeepUpdate(user) + fields.DeepUpdate(user.Clone()) } event.Timestamp = start @@ -370,10 +372,13 @@ func resolveErr(host string, err error) (common.MapStr, []TaskRunner, error) { func WithFields(fields common.MapStr, r TaskRunner) TaskRunner { return MakeCont(func() (common.MapStr, []TaskRunner, error) { event, cont, err := r.Run() - if event == nil { + if event != nil { + event = event.Clone() + event.DeepUpdate(fields) + } else if err != nil { event = common.MapStr{} + event.DeepUpdate(fields) } - event.DeepUpdate(fields) for i := range cont { cont[i] = WithFields(fields, cont[i])