Skip to content

Commit 4d53320

Browse files
authored
Make monitoring Namespace thread-safe (#22640)
Add a mutex to Namespace to make read/writes thread-safe. Fixes #22639
1 parent 24a4da8 commit 4d53320

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

libbeat/monitoring/namespace.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var namespaces = NewNamespaces()
2323

2424
// Namespace contains the name of the namespace and it's registry
2525
type Namespace struct {
26+
sync.Mutex
2627
name string
2728
registry *Registry
2829
}
@@ -42,11 +43,15 @@ func GetNamespace(name string) *Namespace {
4243

4344
// SetRegistry sets the registry of the namespace
4445
func (n *Namespace) SetRegistry(r *Registry) {
46+
n.Lock()
47+
defer n.Unlock()
4548
n.registry = r
4649
}
4750

4851
// GetRegistry gets the registry of the namespace
4952
func (n *Namespace) GetRegistry() *Registry {
53+
n.Lock()
54+
defer n.Unlock()
5055
if n.registry == nil {
5156
n.registry = NewRegistry()
5257
}

0 commit comments

Comments
 (0)