Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent concurrent map writes to c.UnusedFields #11311

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -65,9 +66,10 @@ var (
// will be logging to, as well as all the plugins that the user has
// specified
type Config struct {
toml *toml.Config
errs []error // config load errors.
UnusedFields map[string]bool
toml *toml.Config
errs []error // config load errors.
UnusedFields map[string]bool
unusedFieldsMutex *sync.Mutex

Tags map[string]string
InputFilters []string
Expand All @@ -91,7 +93,8 @@ type Config struct {
// once the configuration is parsed.
func NewConfig() *Config {
c := &Config{
UnusedFields: map[string]bool{},
UnusedFields: map[string]bool{},
unusedFieldsMutex: &sync.Mutex{},

// Agent defaults:
Agent: &AgentConfig{
Expand Down Expand Up @@ -1846,7 +1849,9 @@ func (c *Config) missingTomlField(_ reflect.Type, key string) error {

// ignore fields that are common to all plugins.
default:
c.unusedFieldsMutex.Lock()
c.UnusedFields[key] = true
c.unusedFieldsMutex.Unlock()
}
return nil
}
Expand Down