Fix exec hang and stop timeout#1926
Open
lakshitsoni26 wants to merge 3 commits into
Open
Conversation
Ensure the exec session process is cleaned up when the client connection drops (e.g. broken pipe, SSH drop, SIGHUP), preventing zombie processes from hanging subsequent exec sessions.
Wrap the lock acquisition and graceful stop in a TaskGroup that enforces the timeout. This ensures that if the lock is held indefinitely by a hung exec session, the container is forcefully killed after the timeout.
3 tasks
stephenlclarke
added a commit
to stephenlclarke/container
that referenced
this pull request
Jul 9, 2026
Port the useful exec-session cleanup shape from apple#1926 into the Stephen runtime lane without pushing to Apple. The containerCreateProcess XPC route now keeps its XPCServerSession, and the harness registers disconnect cleanup for client-attached ad hoc exec processes. Detached exec processes keep their existing Docker-compatible lifetime and are not killed when the CLI connection closes. This improves container-compose exec and lifecycle reliability by preventing orphaned attached exec sessions from blocking later exec or stop operations. Release-Highlight: Improves container compose exec reliability by killing attached exec processes when the client disconnects, preventing orphaned sessions from blocking later exec or stop operations while preserving detached exec; ports the useful cleanup from apple#1926 for apple#1916.
3 tasks
When the guest agent disconnects unexpectedly (e.g. because of the PTY closing on the host), the host tries to forward SIGKILL to the agent but hits a `clientIsStopped` exception from GRPC, leaving waiters hung. This catches that exception and cleanly releases waiters. Credit: Bug found by @stephenlclarke.
Author
|
Fix clientIsStopped error when sending signal to dead agent When the guest agent disconnects unexpectedly (e.g. because of the PTY closing on the host), the host tries to forward SIGKILL to the agent but hits a Credit: Bug found by @stephenlclarke. |
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.
Fixes #1916
Type of Change
Motivation and Context
This PR resolves a critical bug where
container execandcontainer stopcommands hang indefinitely when an SSH session disconnects abruptly (or the terminal window is closed without cleanly exiting).The underlying issues were identified and addressed in two distinct commits:
execattempts would try to acquire the same resources, hit a blocking read/write on a dead file descriptor, and hang indefinitely. This was fixed by registering anonDisconnectlistener inContainersHarnessto forcefully kill the specific orphaned process upon a client disconnect.container stopcommand completely ignored thestopTimeoutSecondsflag if an exec session was blocking theRuntimeServiceactor lock. This PR wraps the lock acquisition and the graceful stop sequence inside awithThrowingTaskGroup. This ensures that even if an exec session is infinitely holding the lock, the container is forcefully killed if it doesn't shut down within the designated 5-second timeout window.Fixing these primary issues also inherently prevents the secondary symptom where
container listincorrectly reports the container asrunningwhilecontainer execfails.Testing
Local Test Verification: