CLI: Fix hang with exec/run -i with self-exiting command and open stdin - #40921
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a client-side hang in wslc container exec -i/-it when stdin is redirected to a synchronous (non-overlapped) pipe and the remote process exits without consuming stdin. The fix ensures the stdin relay worker can always be interrupted during teardown, matching the expected docker exec -i behavior.
Changes:
- Add a shared teardown helper in
ConsoleServicethat signals the exit event and repeatedly callsCancelSynchronousIobefore joining the stdin relay thread. - Treat
ERROR_OPERATION_ABORTEDfromReadFileas EOF in the relay read path so cancellation cleanly terminates the relay loop. - Add two E2E regression tests covering
exec -iandexec -itwith a self-exiting command while keeping stdin open.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/windows/wslc/e2e/WSLCE2EContainerExecTests.cpp | Adds regression tests asserting exec -i/-it echo hello exits without requiring client stdin closure. |
| src/windows/wslc/services/ConsoleService.cpp | Introduces teardown logic to interrupt synchronous stdin reads (via CancelSynchronousIo) before joining relay worker threads. |
| src/windows/common/relay.cpp | Maps ERROR_OPERATION_ABORTED from ReadFile to EOF (0 bytes) to allow canceled reads to end relay loops cleanly. |
David Bennett (dkbennett)
marked this pull request as ready for review
June 26, 2026 22:50
David Bennett (dkbennett)
marked this pull request as draft
June 26, 2026 22:51
Blue (OneBlue)
approved these changes
Jun 29, 2026
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.
Summary of the Pull Request
wslc exec -i <container> echo hello didn't return until the client's stdin was closed, while  docker exec -i returns as soon as the process exits. The hang is entirely clientâside.When wslc's stdin is a pipe (not a console), the stdin relay runs on a worker thread blocked in a synchronous  ReadFile . That read can't be interrupted by the relay's exit event. So when the remote process exits and teardown tries to  join() the worker, the join blocks until stdin is closed externally â the hang.
The fix
A shared teardown helper,  InterruptAndJoinInputThread (used by both the TTY and nonâTTY relay paths), now signals the exit event and then calls  CancelSynchronousIo on the worker (retried until it exits) before joining â which aborts the otherwiseâuninterruptible read. A matching oneâline change in  relay.cpp treats the resulting  ERROR_OPERATION_ABORTED as EOF so the relay loop ends cleanly. Termination is guaranteed: every state the worker can block in is broken by either the cancel or the alreadyâset exit event.
Two regression tests are also added which exercise this hang and I confirmed these tests fail without the fix, and pass with the fix.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Tests
Two regression tests run a selfâexiting command ( echo hello ) and assert the process exits before stdin is closed â one for  exec -i , one for  exec -it , since the two paths have separate teardown logic that could regress independently. Both detect the symptom (process must exit within the timeout), so any teardown hang fails the test.
These tests fail without the fix and pass with the fix.