Skip to content

fix: add mutex to protect Worker.Platforms from data race - #6867

Merged
crazy-max merged 1 commit into
moby:masterfrom
okhowang:fix/platforms-data-race
Jun 12, 2026
Merged

crazy-max merged 1 commit into
moby:masterfrom
okhowang:fix/platforms-data-race

Conversation

@okhowang

Copy link
Copy Markdown
Contributor

When noCache=true, Platforms() appends to w.WorkerOpt.Platforms. Concurrent gRPC calls to ListWorkers (each handled in a separate goroutine) can cause a data race where one goroutine creates matchers with length N, while another appends new platforms, causing the first goroutine's range to exceed matchers bounds:

panic: runtime error: index out of range [81] with length 81

Add sync.Mutex to serialize access to Platforms().

Fixes #6866

When noCache=true, Platforms() appends to w.WorkerOpt.Platforms.
Concurrent gRPC calls to ListWorkers (each handled in a separate
goroutine) can cause a data race where one goroutine creates matchers
with length N, while another appends new platforms, causing the first
goroutine's range to exceed matchers bounds:

  panic: runtime error: index out of range [81] with length 81

Add sync.Mutex to serialize access to Platforms().

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
@okhowang
okhowang force-pushed the fix/platforms-data-race branch from e52c157 to e26b5d4 Compare June 12, 2026 02:32
okhowang added a commit to okhowang/moby that referenced this pull request Jun 12, 2026
@crazy-max crazy-max added this to the v0.31.0 milestone Jun 12, 2026

@crazy-max crazy-max left a comment •

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.

LGTM thanks!

For follow-up we could maybe have a regression test. Making it deterministic might be annoying because archutil.SupportedPlatforms(true) depends on host/binfmt state.

@crazy-max
crazy-max merged commit d31ba4a into moby:master Jun 12, 2026
239 of 241 checks passed
@okhowang
okhowang deleted the fix/platforms-data-race branch June 12, 2026 12:28
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.

Data race in Worker.Platforms() causes panic: runtime error: index out of range

2 participants