Skip to content

solver: lock before using actives#3938

Merged
tonistiigi merged 1 commit intomoby:masterfrom
alexcb:lock-list-mu-before-accessing-actives
Jun 8, 2023
Merged

solver: lock before using actives#3938
tonistiigi merged 1 commit intomoby:masterfrom
alexcb:lock-list-mu-before-accessing-actives

Conversation

@alexcb
Copy link
Copy Markdown
Collaborator

@alexcb alexcb commented Jun 7, 2023

This fixes:

fatal error: concurrent map read and map write
goroutine 151083 [running]:
github.com/moby/buildkit/solver.(*Job).walkProvenance(0xc0005663c0, {0x1cf5008, 0xc00b1270e0}, {0x47?, {0x1cf7e60?, 0xc006e4a680?}}, 0xc00a1fc690, 0xc0200a7d28?)
        /src/solver/jobs.go:545 +0x105
github.com/moby/buildkit/solver.(*Job).walkProvenance(0xc0005663c0, {0x1cf5008, 0xc00b1270e0}, {0x47?, {0x1cf7e60?, 0xc006e4a880?}}, 0xc00a1fc690, 0x163d22c9738c10eb?)
        /src/solver/jobs.go:556 +0x273
github.com/moby/buildkit/solver.(*Job).walkProvenance(0xc0005663c0, {0x1cf5008, 0xc00b1270e0}, {0x47?, {0x1cf7e60?, 0xc006e4a900?}}, 0xc00a1fc690, 0x0?)
        /src/solver/jobs.go:556 +0x273
github.com/moby/buildkit/solver.(*Job).walkProvenance(0xc0005663c0, {0x1cf5008, 0xc00b1270e0}, {0x47?, {0x1cf7e60?, 0xc006e4aac0?}}, 0xc00a1fc690, 0x416190?)
        /src/solver/jobs.go:556 +0x273
github.com/moby/buildkit/solver.(*Job).walkProvenance(0xc0005663c0, {0x1cf5008, 0xc00b1270e0}, {0x47?, {0x1cf7e60?, 0xc006e4acc0?}}, 0xc00a1fc690, 0x80?)
        /src/solver/jobs.go:556 +0x273
github.com/moby/buildkit/solver.(*Job).walkProvenance(0xc0005663c0, {0x1cf5008, 0xc00b1270e0}, {0xc0200a7d60?, {0x1cf7e60?, 0xc006e4ad40?}}, 0xc00a1fc690, 0xc001754d98?)
        /src/solver/jobs.go:556 +0x273
github.com/moby/buildkit/solver.(*withProvenance).WalkProvenance(0xc0135f0cf0, {0x1cf5008, 0xc00b1270e0}, 0x18cf520?)
        /src/solver/jobs.go:537 +0xe5
github.com/moby/buildkit/solver/llbsolver.captureProvenance({0x1cf5008, 0xc00b1270e0}, {0x1cf9a30, 0xc0135f0cf0})
        /src/solver/llbsolver/provenance.go:266 +0xaf
github.com/moby/buildkit/solver/llbsolver.(*resultProxy).Result.func2({0x1cf5008, 0xc00b1270e0})
        /src/solver/llbsolver/bridge.go:347 +0x3bb
github.com/moby/buildkit/util/flightcontrol.(*call).run(0xc01fded440)
        /src/util/flightcontrol/flightcontrol.go:121 +0x5e
sync.(*Once).doSlow(0x1cf5008?, 0xc00d7cfea0?)
        /usr/local/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(0xc01a9fc790?, 0xc00152cae0?)
        /usr/local/go/src/sync/once.go:65 +0x1f
created by github.com/moby/buildkit/util/flightcontrol.(*call).wait
        /src/util/flightcontrol/flightcontrol.go:164 +0x44f

Copy link
Copy Markdown
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

I wonder if we should just do one lock in WalkProvenance? Doing the lock/unlock separately for each vertex may have a bigger overhead.

Comment thread solver/jobs.go Outdated
@alexcb alexcb force-pushed the lock-list-mu-before-accessing-actives branch from 906e3a5 to 4ddb9e8 Compare June 8, 2023 15:33
Job.walkProvenance needs to acquire a read lock before accessing
j.list.actives.

The actual lock is acquired/released under WalkProvenance to prevent
multiple locks/unlocks while walkProvenance recurses.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
@alexcb alexcb force-pushed the lock-list-mu-before-accessing-actives branch from 4ddb9e8 to 09325e7 Compare June 8, 2023 15:38
@alexcb alexcb requested a review from tonistiigi June 8, 2023 18:02
@tonistiigi tonistiigi merged commit 3c4e8f5 into moby:master Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants