Skip to content

Fix concurrency issues with source policy - #6448

Merged
tonistiigi merged 1 commit into
moby:masterfrom
cpuguy83:more_sourcepol_panics
Jan 7, 2026
Merged

tonistiigi merged 1 commit into
moby:masterfrom
cpuguy83:more_sourcepol_panics

Conversation

@cpuguy83

@cpuguy83 cpuguy83 commented Jan 6, 2026

Copy link
Copy Markdown
Member

This is more stuff where we weren't accounting for concurrent access.

Seen this on latest buildx stable image:

fatal error: concurrent map writes

goroutine 23041 [running]:
internal/runtime/maps.fatal({0x2068176?, 0x1d660e0?})
	/usr/local/go/src/runtime/panic.go:1046 +0x18
github.com/moby/buildkit/sourcepolicy.(*wildcardCache).Match(0xc003813a30, {0xc001f020c0, 0x3e})
	/src/sourcepolicy/formatter.go:66 +0xbf
github.com/moby/buildkit/sourcepolicy.match(0xc0055ed320, {0xc001f020c0, 0x3e}, {0x0, 0x0, 0xc0027fa2a0?}, 0x0)
	/src/sourcepolicy/matcher.go:56 +0x48f
github.com/moby/buildkit/sourcepolicy.(*Engine).evaluatePolicy(0xc002ccb5c0, {0x23ad8b8, 0xc0026926c0}, 0xc001cdaaa0, 0xc00344cd40)
	/src/sourcepolicy/engine.go:133 +0x305
github.com/moby/buildkit/sourcepolicy.(*Engine).evaluatePolicies(0xc002ccb5c0, {0x23ad8b8, 0xc0026926c0}, 0xc00344cd40)
	/src/sourcepolicy/engine.go:101 +0x7a
github.com/moby/buildkit/sourcepolicy.(*Engine).Evaluate(0xc002ccb5c0, {0x23ad8f0, 0xc001cdaa50}, 0xc00344cd40)
	/src/sourcepolicy/engine.go:84 +0x312
github.com/moby/buildkit/solver/llbsolver.(*policyEvaluator).Evaluate(0xc002f8f950, {0x23ad8f0, 0xc001cdaa50}, 0xc003d10420)
	/src/solver/llbsolver/policy.go:27 +0x90
github.com/moby/buildkit/solver/llbsolver.loadLLB.func1()
	/src/solver/llbsolver/vertex.go:353 +0x6e
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/src/vendor/golang.org/x/sync/errgroup/errgroup.go:93 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 22895
	/src/vendor/golang.org/x/sync/errgroup/errgroup.go:78 +0x95

Comment thread sourcepolicy/formatter.go Outdated

// Source wraps a protobuf source in order to store cached state such as the compiled regexes.
type selectorCache struct {
mu sync.Mutex

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to use sync.OnceValue for re/w in here instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, I think this is what you meant?

This is more stuff where we weren't accounting for concurrent access.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83
cpuguy83 force-pushed the more_sourcepol_panics branch from 84bfc9c to f7682fe Compare January 6, 2026 23:42
@cpuguy83

cpuguy83 commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

Fixed a stray newline causing lint failure.

@tonistiigi
tonistiigi merged commit 6ca9d54 into moby:master Jan 7, 2026
140 checks passed
@cpuguy83
cpuguy83 deleted the more_sourcepol_panics branch January 7, 2026 01:31
@crazy-max crazy-max added this to the v0.27.0 milestone Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants