Skip to content

Fix shim fully drain stdin on close IO#246

Open
austinvazquez wants to merge 3 commits into
containerd:mainfrom
austinvazquez:fix/fully-drain-io-copystreams
Open

Fix shim fully drain stdin on close IO#246
austinvazquez wants to merge 3 commits into
containerd:mainfrom
austinvazquez:fix/fully-drain-io-copystreams

Conversation

@austinvazquez

@austinvazquez austinvazquez commented Jul 2, 2026

Copy link
Copy Markdown
Member

This change addresses and edge case where draining stdin on close will truncate data.

Ref: https://github.com/containerd/nerdbox/actions/runs/28613973997/job/84853144969?pr=245

--- FAIL: TestShim (44.19s)
    --- FAIL: TestShim/LargeStdioRoundTrip (0.48s)
        exec_suite.go:743: got 20959232 bytes, want 20971520 (truncated by 12288 bytes)

Copilot AI review requested due to automatic review settings July 2, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the shim’s stdin forwarding logic to ensure that when CloseIO fires, any remaining bytes already buffered on the stdin reader are fully drained and forwarded before the shim sends an in-band EOF (CloseWrite) to the guest.

Changes:

  • Replace the single “drain one read” behavior on CloseIO with a loop that continues reading/writing until the stdin reader returns EOF or an error.
  • Expand the in-code rationale to document why a single read can truncate stdin under backpressure (e.g., slow guest consumption / vsock credit).

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

Comment thread internal/shim/task/io_copystreams.go Outdated
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch 2 times, most recently from 2316bcb to f054a26 Compare July 2, 2026 22:23
Copilot AI review requested due to automatic review settings July 2, 2026 22:23
@austinvazquez
austinvazquez marked this pull request as ready for review July 2, 2026 22:23
@austinvazquez austinvazquez changed the title fix(task): fully drain stdin on close Fix shim fully drain stdin on close IO Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/shim/task/io_copystreams.go Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 02:37
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from f054a26 to e4ed4c7 Compare July 8, 2026 02:37
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread internal/shim/task/io_copystreams.go Outdated
Comment thread internal/shim/task/io_copystreams_test.go Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 02:55
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from e4ed4c7 to d7b7250 Compare July 8, 2026 02:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/shim/task/io_copystreams.go Outdated
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
Copilot AI review requested due to automatic review settings July 8, 2026 03:01
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from d7b7250 to 9d9e93b Compare July 8, 2026 03:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/shim/task/io_copystreams.go Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 00:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread internal/shim/task/io_copystreams.go
Comment thread internal/shim/task/io_copystreams.go Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 01:14
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from d712055 to 4638837 Compare July 10, 2026 01:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines 786 to +787
if stdinEOF != nil {
if err := stdinEOF(); err != nil {
if err := stdinEOF(ctx); err != nil {
Comment thread internal/shim/task/io_copystreams.go
Copilot AI review requested due to automatic review settings July 10, 2026 01:25
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from 4638837 to b3e1a31 Compare July 10, 2026 01:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

internal/shim/task/service.go:794

  • CloseIO now blocks waiting for stdin drain/EOF via stdinEOF(ctx). If the incoming RPC context has no deadline (common in tests and potentially in callers), and the FIFO write end is never closed, this can block indefinitely and tie up a shim handler goroutine. Consider applying a server-side timeout when ctx has no deadline (similar to forwardIO's ioShutdown safety net), so CloseIO can't hang forever on a misbehaving peer.
		if stdinEOF != nil {
			if err := stdinEOF(ctx); err != nil {
				log.G(ctx).WithError(err).WithFields(log.Fields{
					"id":   r.ID,
					"exec": r.ExecID,
				}).Error("failed to send stdin EOF")
				return nil, errgrpc.ToGRPC(err)
			}
			return empty, nil

Comment thread internal/shim/task/io_copystreams_test.go
Copilot AI review requested due to automatic review settings July 10, 2026 12:34
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from b3e1a31 to f801606 Compare July 10, 2026 12:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread internal/shim/task/io_copystreams_windows.go Outdated
Comment thread internal/shim/task/io_copystreams_unix.go Outdated
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
Copilot AI review requested due to automatic review settings July 10, 2026 13:36
@austinvazquez
austinvazquez force-pushed the fix/fully-drain-io-copystreams branch from f801606 to aedb2c0 Compare July 10, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread internal/shim/task/service.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.

2 participants