Skip to content

Serialize concurrent builder ensures with a file lock - #2174

Closed
MayCXC wants to merge 1 commit into
apple:mainfrom
MayCXC:builder-ensure-lock
Closed

Serialize concurrent builder ensures with a file lock#2174
MayCXC wants to merge 1 commit into
apple:mainfrom
MayCXC:builder-ensure-lock

Conversation

@MayCXC

@MayCXC MayCXC commented Aug 27, 2026

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes #2167.

Simultaneous build invocations that find no builder race one another through create, bootstrap, and the failure cleanup: the create loser proceeds against the winner's container, collides with its bootstrap, and the cleanup deletes the container the winner just started, so a cold system under parallel builds may never converge on a running builder.

An advisory flock around the ensure section admits one invocation at a time; whichever enters first creates or repairs the builder and the rest observe the finished state. buildx serializes its builder store the same way: https://github.com/docker/buildx/blob/master/store/store.go

This may be the root cause behind #1072 (dialing a builder hangs with no feedback) and #1159 (builder container gets stuck and cannot be deleted), both of which describe what this race produces.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

Parallel container build invocations from a cold system converge on one running builder instead of deleting each other's.

Integration suite: 397 passed. Unit suite: 772 passed. make fmt, make check clean.

Simultaneous build invocations that find no builder race one another
through create, bootstrap, and the failure cleanup: the create loser
proceeds against the winner's container, collides with its bootstrap,
and the cleanup deletes the container the winner just started, so a
cold system under parallel builds may never converge on a running
builder. An advisory flock around the ensure section admits one
invocation at a time; whichever enters first creates or repairs the
builder and the rest observe the finished state. buildx serializes its
builder store the same way.
https://github.com/docker/buildx/blob/master/store/store.go
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.

[Bug]: Concurrent builds on a system with no builder race through create and delete the builder one of them started

2 participants