Skip to content

cmd: workaround conpty race condition in Start() - #2923

Open
mcayland-ntx wants to merge 1 commit into
microsoft:mainfrom
mcayland-ntx:fix/avoid-conpty-race-with-no-stdin
Open

mcayland-ntx wants to merge 1 commit into
microsoft:mainfrom
mcayland-ntx:fix/avoid-conpty-race-with-no-stdin

Conversation

@mcayland-ntx

Copy link
Copy Markdown

conpty has a known race condition when attaching a terminal to a starting process that does not have a Stdin handle, causing the process to exit immediately with a 0xc000013a (STATUS_CONTROL_C_EXIT) error. This is easily noticed when launching a container using nerdctl in detached terminal mode which uses BinaryIO where only the Stdout and Stderr handles are created for the target process. Attempting to start a target process in this configuration results in a process start success rate of less than 5%.

Since the race condition in conpty is unlikely to be fixed in the short term, add a workaround to ensure that a Stdin handle is always created for container processes launched with terminal mode enabled. This allows a container started using nerdctl in detached terminal mode to always start successfully.

Resolves #2831

@mcayland-ntx

Copy link
Copy Markdown
Author

Ping? Justin (@jterry75) is this something that you could help with? Or at least approve the CI run so we can make sure that nothing breaks :)

@jterry75

Copy link
Copy Markdown
Contributor

Code seems harmless. Do you have a link to the conpty bug? I'd like it in the comments at least.

@jterry75

Copy link
Copy Markdown
Contributor

Running checks now to get get some coverage for ya, but I'd still like the comment before merge.

@mcayland-ntx

Copy link
Copy Markdown
Author

Code seems harmless. Do you have a link to the conpty bug? I'd like it in the comments at least.

I don't believe there is an official bug for it? However the behaviour has been reported elsewhere by other conpty users as per my comment in #2831 (comment), and in addition that same issue is referenced by moby who are also seeing similar problems.

@mcayland-ntx

Copy link
Copy Markdown
Author

Running checks now to get get some coverage for ya, but I'd still like the comment before merge.

I've had some emails over the weekend indicating that the CI Actions have expired. Looks like I can't manually re-run them without re-pushing...

conpty has a known race condition when attaching a terminal to a starting
process that does not have a Stdin handle, causing the process to exit
immediately with a 0xc000013a (STATUS_CONTROL_C_EXIT) error. This is easily
noticed when launching a container using nerdctl in detached terminal mode
which uses BinaryIO where only the Stdout and Stderr handles are created for
the target process. Attempting to start a target process in this configuration
results in a process start success rate of less than 5%.

Since the race condition in conpty is unlikely to be fixed in the short
term, add a workaround to ensure that a Stdin handle is always created for
container processes launched with terminal mode enabled. This allows a
container started using nerdctl in detached terminal mode to always start
successfully.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
@mcayland-ntx
mcayland-ntx force-pushed the fix/avoid-conpty-race-with-no-stdin branch from f2ec7be to 49e41ff Compare October 19, 2026 08:32
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.

Stdin handle required to avoid conpty race condition upon WCOW container startup with terminal

3 participants