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

Go tests detecting race cataloging packages #1633

Closed
James-Pickett opened this issue Feb 28, 2023 · 0 comments · Fixed by #1639
Closed

Go tests detecting race cataloging packages #1633

James-Pickett opened this issue Feb 28, 2023 · 0 comments · Fixed by #1639
Labels
bug Something isn't working

Comments

@James-Pickett
Copy link

What happened:

running go test -race using test below results in failure

func TestRace(t *testing.T) {
        // using path to git binary as an example
	src, _ := source.NewFromFile("/opt/homebrew/Cellar/git/2.39.2/bin/git")
	syft.CatalogPackages(&src, cataloger.DefaultConfig())
}
❯  go test -race
==================
WARNING: DATA RACE
Read at 0x00c0004cab80 by goroutine 17:
  github.com/wagoodman/go-progress.(*Manual).SetCompleted()
      /Users/jamespickett/go/pkg/mod/github.com/wagoodman/go-progress@v0.0.0-20200731105512-1020f39e6240/manual.go:31 +0x90c
  github.com/anchore/syft/syft/pkg/cataloger.Catalog()
      /Users/jamespickett/go/pkg/mod/github.com/anchore/syft@v0.73.0/syft/pkg/cataloger/catalog.go:176 +0x898
  github.com/anchore/syft/syft.CatalogPackages()
      /Users/jamespickett/go/pkg/mod/github.com/anchore/syft@v0.73.0/syft/lib.go:72 +0x7ac
  github.com/kolide/launcher/pkg/osquery/tables/syft.TestRace()
      /Users/jamespickett/Documents/repos/james-launcher/pkg/osquery/tables/syft/table_test.go:13 +0x190
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1446 +0x188
  testing.(*T).Run.func1()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1493 +0x40

Previous write at 0x00c0004cab80 by goroutine 19:
  github.com/anchore/syft/syft/pkg/cataloger.Catalog.func2()
      /Users/jamespickett/go/pkg/mod/github.com/anchore/syft@v0.73.0/syft/pkg/cataloger/catalog.go:142 +0x58

Goroutine 17 (running) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1493 +0x55c
  testing.runTests.func1()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1846 +0x90
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1446 +0x188
  testing.runTests()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1844 +0x6c0
  testing.(*M).Run()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1726 +0x870
  main.main()
      _testmain.go:47 +0x2fc

Goroutine 19 (finished) created at:
  github.com/anchore/syft/syft/pkg/cataloger.Catalog()
      /Users/jamespickett/go/pkg/mod/github.com/anchore/syft@v0.73.0/syft/pkg/cataloger/catalog.go:140 +0x548
  github.com/anchore/syft/syft.CatalogPackages()
      /Users/jamespickett/go/pkg/mod/github.com/anchore/syft@v0.73.0/syft/lib.go:72 +0x7ac
  github.com/kolide/launcher/pkg/osquery/tables/syft.TestRace()
      /Users/jamespickett/Documents/repos/james-launcher/pkg/osquery/tables/syft/table_test.go:13 +0x190
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1446 +0x188
  testing.(*T).Run.func1()
      /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1493 +0x40
==================
--- FAIL: TestRace (0.04s)
    testing.go:1319: race detected during execution of test
FAIL
exit status 1
FAIL    github.com/kolide/launcher/pkg/osquery/tables/syft      0.344s

What you expected to happen:

No race to be detected, tests pass

Steps to reproduce the issue:

Run the test code above using go test -race

Anything else we need to know?:

It does not race for all paths. A complied go executable does not race.

Also, thank you for creating this awesome tool!

Environment:

  • Output of syft version:
// go mod
github.com/anchore/syft v0.73.0
❯  syft version
Application:        syft
Version:            0.73.0
JsonSchemaVersion:  7.0.0
BuildDate:          2023-02-22T19:08:35Z
GitCommit:          aa151da5fe2a1b11502c852fd2d3ad462c1d245f
GitDescription:     [not provided]
Platform:           darwin/arm64
GoVersion:          go1.20.1
Compiler:           gc
  • OS (e.g: cat /etc/os-release or similar):
    MacBook Pro
    Apple M1 Pro
    Ventura 13.2.1
@James-Pickett James-Pickett added the bug Something isn't working label Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant