Skip to content

core/runtime/v2: fix race on Windows deferredPipeConnection.c in Read#13462

Merged
mxpv merged 1 commit into
containerd:mainfrom
austinvazquez:fix-core-runtime-data-race-on-windows
May 27, 2026
Merged

core/runtime/v2: fix race on Windows deferredPipeConnection.c in Read#13462
mxpv merged 1 commit into
containerd:mainfrom
austinvazquez:fix-core-runtime-data-race-on-windows

Conversation

@austinvazquez

Copy link
Copy Markdown
Member

Read short-circuited on if dpc.c == nil before calling dpc.wg.Wait() which races with the dialer goroutine spawned in openShimLog. The dialer assigns dpc.c = c (and may set dpc.conerr) outside any lock; the only synchronization is the WaitGroup, and Read skipped it on the fast path.

Redacted stack trace:

==================
  WARNING: DATA RACE
  Write at 0x00c00xxxxxxx by goroutine N:
    github.com/containerd/containerd/v2/core/runtime/v2.openShimLog.func1()
        core/runtime/v2/shim_windows.go:84

  Previous read at 0x00c00xxxxxxx by goroutine M:
    github.com/containerd/containerd/v2/core/runtime/v2.(*deferredPipeConnection).Read()
        core/runtime/v2/shim_windows.go:45
    io.copyBuffer()
        io/io.go:429
    io.Copy()
        io/io.go:388
    os.genericReadFrom()
        os/file.go:205
    os.(*File).ReadFrom()
        os/file.go:181
    io.copyBuffer()
        io/io.go:415
    io.Copy()
        io/io.go:388
    github.com/containerd/containerd/v2/core/runtime/v2.(*binary).Start.func3()
        core/runtime/v2/binary.go:106

  Goroutine N (running) created at:
    sync.(*WaitGroup).Go()
        sync/waitgroup.go:238
    github.com/containerd/containerd/v2/core/runtime/v2.(*binary).Start()
        core/runtime/v2/binary.go:92
    github.com/containerd/containerd/v2/core/runtime/v2.(*ShimManager).startShim()
        core/runtime/v2/shim_manager.go:323
    github.com/containerd/containerd/v2/core/runtime/v2.(*ShimManager).Start()
        core/runtime/v2/shim_manager.go:282
    github.com/containerd/containerd/v2/core/runtime/v2.(*TaskManager).Create()
        core/runtime/v2/task_manager.go:213
    go.etcd.io/bbolt.(*Bucket).spill()
        [bbolt internal frames elided]
    github.com/containerd/containerd/v2/core/mount/manager.(*mountManager).Activate()
        core/mount/manager/manager.go:501
    go.etcd.io/bbolt.(*DB).Update()
        [bbolt internal frames elided]
    github.com/containerd/containerd/v2/core/mount/manager.(*mountManager).Activate()
        core/mount/manager/manager.go:246
    github.com/containerd/containerd/v2/core/runtime/v2.(*TaskManager).Create()
        core/runtime/v2/task_manager.go:189
    github.com/containerd/containerd/v2/plugins/services/tasks.(*local).Create()
        plugins/services/tasks/local.go:256
    github.com/containerd/containerd/v2/client.(*container).NewTask()
        client/container.go:295
    [application: container-start handler chain elided]
    net/http.serverHandler.ServeHTTP()
        net/http/server.go:3311
    net/http.(*conn).serve()
        net/http/server.go:2073
    net/http.(*Server).Serve.gowrap3()
        net/http/server.go:3464

  Goroutine M (running) created at:
    github.com/containerd/containerd/v2/core/runtime/v2.(*binary).Start()
        core/runtime/v2/binary.go:104
    [same shim-startup path as Goroutine N above]
  ==================

Read short-circuited on `if dpc.c == nil` before calling
`dpc.wg.Wait()` which races with the dialer goroutine spawned in
openShimLog. The dialer assigns `dpc.c = c` (and may set `dpc.conerr`)
outside any lock; the only synchronization is the WaitGroup, and Read
skipped it on the fast path.

Signed-off-by: Austin Vazquez <[email protected]>
Copilot AI review requested due to automatic review settings May 21, 2026 22:20
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review May 21, 2026
@austinvazquez austinvazquez added cherry-pick/2.3.x Change to be cherry picked to release/2.3 platform/windows Windows labels May 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Windows-specific data race in deferredPipeConnection.Read by ensuring the WaitGroup synchronization is always honored before accessing fields written by the dialer goroutine spawned from openShimLog.

Changes:

  • Move dpc.wg.Wait() to the start of (*deferredPipeConnection).Read to establish a proper happens-before relationship for dpc.c / dpc.conerr.
  • Simplify the Read fast-path to avoid unsynchronized reads of dpc.c.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/runtime/v2/shim_windows.go
@austinvazquez austinvazquez added kind/bug cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch labels May 21, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review May 25, 2026
@mxpv
mxpv added this pull request to the merge queue May 27, 2026
Merged via the queue into containerd:main with commit 34ef231 May 27, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review May 27, 2026
@austinvazquez
austinvazquez deleted the fix-core-runtime-data-race-on-windows branch June 3, 2026 00:46
@austinvazquez

Copy link
Copy Markdown
Member Author

/cherry-pick release/2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@austinvazquez: new pull request created: #13522

Details

In response to this:

/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 kind/bug platform/windows Windows size/XS

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants