mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
fix: remove race when writing errors in generic cataloger (#3875)
* fix generic cataloger race Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * update race test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
parent
a7816dc9e7
commit
abe5e27b4b
@ -221,7 +221,8 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- "go test -v ./cmd/syft/internal/test/integration"
|
- "go test -v ./cmd/syft/internal/test/integration"
|
||||||
# exercise most of the CLI with the data race detector
|
# exercise most of the CLI with the data race detector
|
||||||
- "go run -race cmd/syft/main.go alpine:latest"
|
# we use a larger image to ensure we're using multiple catalogers at a time
|
||||||
|
- "go run -race cmd/syft/main.go anchore/test_images:grype-quality-dotnet-69f15d2"
|
||||||
|
|
||||||
validate-cyclonedx-schema:
|
validate-cyclonedx-schema:
|
||||||
desc: Validate that Syft produces valid CycloneDX documents
|
desc: Validate that Syft produces valid CycloneDX documents
|
||||||
|
|||||||
@ -154,7 +154,6 @@ func (c *Cataloger) Name() string {
|
|||||||
func (c *Cataloger) Catalog(ctx context.Context, resolver file.Resolver) ([]pkg.Package, []artifact.Relationship, error) {
|
func (c *Cataloger) Catalog(ctx context.Context, resolver file.Resolver) ([]pkg.Package, []artifact.Relationship, error) {
|
||||||
var packages []pkg.Package
|
var packages []pkg.Package
|
||||||
var relationships []artifact.Relationship
|
var relationships []artifact.Relationship
|
||||||
var errs error
|
|
||||||
|
|
||||||
lgr := log.Nested("cataloger", c.upstreamCataloger)
|
lgr := log.Nested("cataloger", c.upstreamCataloger)
|
||||||
|
|
||||||
@ -167,7 +166,7 @@ func (c *Cataloger) Catalog(ctx context.Context, resolver file.Resolver) ([]pkg.
|
|||||||
pkgs []pkg.Package
|
pkgs []pkg.Package
|
||||||
rels []artifact.Relationship
|
rels []artifact.Relationship
|
||||||
}
|
}
|
||||||
errs = sync.Collect(&ctx, cataloging.ExecutorFile, sync.ToSeq(c.selectFiles(resolver)), func(req request) (result, error) {
|
errs := sync.Collect(&ctx, cataloging.ExecutorFile, sync.ToSeq(c.selectFiles(resolver)), func(req request) (result, error) {
|
||||||
location, parser := req.Location, req.Parser
|
location, parser := req.Location, req.Parser
|
||||||
|
|
||||||
log.WithFields("path", location.RealPath).Trace("parsing file contents")
|
log.WithFields("path", location.RealPath).Trace("parsing file contents")
|
||||||
@ -175,9 +174,9 @@ func (c *Cataloger) Catalog(ctx context.Context, resolver file.Resolver) ([]pkg.
|
|||||||
discoveredPackages, discoveredRelationships, err := invokeParser(ctx, resolver, location, lgr, parser, &env)
|
discoveredPackages, discoveredRelationships, err := invokeParser(ctx, resolver, location, lgr, parser, &env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// parsers may return errors and valid packages / relationships
|
// parsers may return errors and valid packages / relationships
|
||||||
errs = unknown.Append(errs, location, err)
|
err = unknown.New(location, err)
|
||||||
}
|
}
|
||||||
return result{discoveredPackages, discoveredRelationships}, errs
|
return result{discoveredPackages, discoveredRelationships}, err
|
||||||
}, func(_ request, res result) {
|
}, func(_ request, res result) {
|
||||||
for _, p := range res.pkgs {
|
for _, p := range res.pkgs {
|
||||||
p.FoundBy = c.upstreamCataloger
|
p.FoundBy = c.upstreamCataloger
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user