Fix shim fully drain stdin on close IO#246
Open
austinvazquez wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
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
CloseIOwith 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.
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
2 times, most recently
from
July 2, 2026 22:23
2316bcb to
f054a26
Compare
austinvazquez
marked this pull request as ready for review
July 2, 2026 22:23
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 8, 2026 02:37
f054a26 to
e4ed4c7
Compare
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 8, 2026 02:56
e4ed4c7 to
d7b7250
Compare
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 8, 2026 03:01
d7b7250 to
9d9e93b
Compare
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 10, 2026 01:14
d712055 to
4638837
Compare
Comment on lines
786
to
+787
| if stdinEOF != nil { | ||
| if err := stdinEOF(); err != nil { | ||
| if err := stdinEOF(ctx); err != nil { |
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 10, 2026 01:25
4638837 to
b3e1a31
Compare
There was a problem hiding this comment.
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
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 10, 2026 12:34
b3e1a31 to
f801606
Compare
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
austinvazquez
force-pushed
the
fix/fully-drain-io-copystreams
branch
from
July 10, 2026 13:36
f801606 to
aedb2c0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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