Skip to content

Commit

Permalink
Make monitoring Namespace thread-safe (elastic#22640) (elastic#22800)
Browse files Browse the repository at this point in the history
Add a mutex to Namespace to make read/writes thread-safe.

Fixes elastic#22639

(cherry picked from commit 4d53320)
  • Loading branch information
andrewkroh authored Dec 3, 2020
1 parent 046b0cc commit 43314ba
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libbeat/monitoring/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
}
Expand Down

0 comments on commit 43314ba

Please sign in to comment.