From c43ca544112c3eed747c70798a27e47b7d862e1c Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Tue, 17 Nov 2020 19:01:49 -0500 Subject: [PATCH] Make monitoring Namespace thread-safe Add a mutex to Namespace to make read/writes thread-safe. Fixes #22639 --- libbeat/monitoring/namespace.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libbeat/monitoring/namespace.go b/libbeat/monitoring/namespace.go index 5f6d2ed4ae05..5ec11a626e45 100644 --- a/libbeat/monitoring/namespace.go +++ b/libbeat/monitoring/namespace.go @@ -23,6 +23,7 @@ var namespaces = NewNamespaces() // Namespace contains the name of the namespace and it's registry type Namespace struct { + sync.Mutex name string registry *Registry } @@ -42,11 +43,15 @@ func GetNamespace(name string) *Namespace { // SetRegistry sets the registry of the namespace func (n *Namespace) SetRegistry(r *Registry) { + n.Lock() + defer n.Unlock() n.registry = r } // GetRegistry gets the registry of the namespace func (n *Namespace) GetRegistry() *Registry { + n.Lock() + defer n.Unlock() if n.registry == nil { n.registry = NewRegistry() }