- 
                Notifications
    
You must be signed in to change notification settings  - Fork 85
 
Open
Description
The config-parser package has a package-level global variable that causes data races when multiple parser instances are used concurrently:
File: config-parser/parser.go:65
var DefaultSectionName = "" //nolint:gochecknoglobalsWritten at: config-parser/reader.go:198
DefaultSectionName = data.Name  // NO mutex protection!This variable is written by (*configParser).ProcessLine() during parsing without any synchronization, causing race conditions when multiple goroutines parse configurations simultaneously.
This may cause issues like:
==================
WARNING: DATA RACE
Write at 0x000005472da0 by goroutine 1284:
  github.com/haproxytech/client-native/v6/config-parser.(*configParser).ProcessLine()
      /home/runner/go/pkg/mod/github.com/haproxytech/client-native/[email protected]/config-parser/reader.go:198 +0x5fa8
  github.com/haproxytech/client-native/v6/config-parser.(*configParser).Process()
      /home/runner/go/pkg/mod/github.com/haproxytech/client-native/[email protected]/config-parser/reader.go:90 +0x88f
Previous write at 0x000005472da0 by goroutine 1283:
  github.com/haproxytech/client-native/v6/config-parser.(*configParser).ProcessLine()
      /home/runner/go/pkg/mod/github.com/haproxytech/client-native/[email protected]/config-parser/reader.go:198 +0x5fa8
Reproducer:
package main
import (
	"strings"
	"sync"
	"testing"
	parser "github.com/haproxytech/client-native/v6/config-parser"
)
func TestParallelParsing(t *testing.T) {
	config := `
global
	daemon
defaults unnamed_defaults_1
	mode http
backend api
	balance roundrobin
	server srv1 192.168.1.10:80
`
	var wg sync.WaitGroup
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			p, _ := parser.New()
			_ = p.Process(strings.NewReader(config))
		}()
	}
	wg.Wait()
}Run with: go test -race
Metadata
Metadata
Assignees
Labels
No labels