Skip to content

Data race when testing pkg/config #86

@MacroPower

Description

@MacroPower

Highly doubt that this is reproducible without t.Parallel but I would still prefer to fix it.

The strange thing is that I feel sharing here should not be possible, since the YAML marshaler should not be able to use the private fields that CEL is using to store the program. So I must be missing something here.

=== Failed
=== FAIL: pkg/config TestConfig_Write/new_file (0.01s)
    testing.go:1490: race detected during execution of test

=== FAIL: pkg/config TestNewConfigLoaderFromFile (0.00s)
    testing.go:1490: race detected during execution of test
--- PASS: TestNewConfigLoaderFromFile/non-existent_file (0.00s)
--- PASS: TestNewConfigLoaderFromFile/directory_instead_of_file (0.00s)
--- PASS: TestNewConfigLoaderFromFile/valid_file (0.00s)

=== FAIL: pkg/config TestConfig_Write/directory_exists (0.02s)
==================
WARNING: DATA RACE
Write at 0x00c00012bf50 by goroutine 19:
  github.com/macropower/kat/pkg/config_test.TestDefaultConfigYAMLIsValid()
      /home/runner/work/kat/kat/pkg/config/config_test.go:426 +0x48b
  [... CEL parser internal calls snipped ...]
  github.com/google/cel-go/cel.(*Env).Compile()
      /home/runner/go/pkg/mod/github.com/google/cel-go@v0.26.0/cel/env.go:400 +0x54
  github.com/macropower/kat/pkg/expr.(*Environment).Compile()
      /home/runner/work/kat/kat/pkg/expr/expr.go:183 +0xe8
  github.com/macropower/kat/pkg/rule.(*Rule).CompileMatch()
      /home/runner/work/kat/kat/pkg/rule/rule.go:75 +0x88
  github.com/macropower/kat/pkg/command.(*Config).Validate()
      /home/runner/work/kat/kat/pkg/command/config.go:207 +0x725

Previous read at 0x00c00012bf50 by goroutine 55:
  reflect.typedmemmove()
      /opt/hostedtoolcache/go/1.24.5/x64/src/runtime/mbarrier.go:213 +0x0
  [... reflection and YAML encoding calls snipped ...]
  github.com/macropower/kat/pkg/yaml.(*Encoder).Encode()
      /home/runner/work/kat/kat/pkg/yaml/encode.go:20 +0x59b
  github.com/macropower/kat/pkg/config.Config.MarshalYAML()
      /home/runner/work/kat/kat/pkg/config/config.go:114 +0x54f
  github.com/macropower/kat/pkg/config.Config.Write()
      /home/runner/work/kat/kat/pkg/config/config.go:147 +0x41c
  github.com/macropower/kat/pkg/config_test.TestConfig_Write.func5()
      /home/runner/work/kat/kat/pkg/config/config_test.go:248 +0x1fc
  testing.tRunner()
      /opt/hostedtoolcache/go/1.24.5/x64/src/testing/testing.go:1792 +0x225

Goroutine 19 (running) created at:
  [... CEL parser creation chain snipped ...]
  github.com/macropower/kat/pkg/command.init()
      /home/runner/work/kat/kat/pkg/command/config.go:49 +0x11e9
  runtime.doInit1()
      /opt/hostedtoolcache/go/1.24.5/x64/src/runtime/proc.go:7371 +0xd7

Goroutine 55 (running) created at:
  testing.(*T).Run()
      /opt/hostedtoolcache/go/1.24.5/x64/src/testing/testing.go:1851 +0x8f2
  github.com/macropower/kat/pkg/config_test.TestConfig_Write()
      /home/runner/work/kat/kat/pkg/config/config_test.go:242 +0x309
  testing.tRunner()
      /opt/hostedtoolcache/go/1.24.5/x64/src/testing/testing.go:1792 +0x225
==================
    testing.go:1490: race detected during execution of test

=== FAIL: pkg/config TestConfig_Write (0.00s)
=== FAIL: pkg/config TestDefaultConfigFullPipeline (0.07s)
    testing.go:1490: race detected during execution of test
=== FAIL: pkg/config TestDefaultConfigYAMLIsValid (0.07s)
    testing.go:1490: race detected during execution of test

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions