fix: resolve /exit 5-second delay by properly closing transport writer#72
Merged
yishuiliunian merged 2 commits intomainfrom Apr 3, 2026
Merged
fix: resolve /exit 5-second delay by properly closing transport writer#72yishuiliunian merged 2 commits intomainfrom
yishuiliunian merged 2 commits intomainfrom
Conversation
AgentProcess::shutdown() tried drop(self.child.stdin.take()), but stdin was already moved into StdioTransport during spawn. The transport behind Arc had multiple references (AgentProcess + Connection), so the writer was never closed and the child process never received EOF — every exit waited for the 5s grace period before SIGKILL. Fix: add Transport::close() with interior mutability to shut down the writer through any Arc clone. Also fix the child-side shutdown path (forward_loop EOF handler with 2-signal interrupt + abort fallback), add kill_on_drop(true) to shell commands to prevent orphan processes, and give DuplexTransport independent per-side connected flags.
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
/exittook ~5s becauseAgentProcess::shutdown()failed to close stdin (already moved intoStdioTransport). The child never received EOF, triggering the 5s grace period + SIGKILL every time.Transport::close()trait method with interior mutability — shuts down the writer through anyArcclone, bypassing the ownership problem.kill_on_drop(true)to shell commands, and fixedDuplexTransport's shared connected flag.Changes
Transport::close()required trait method; implemented forStdioTransport,TcpTransport,DuplexTransport;Connection::close()delegate;DuplexTransportrefactored to independent per-sideAtomicBool+ consistentRelease/Acquireordering +send()error handlingAgentProcess::shutdown()usestransport.close()instead of brokendrop(child.stdin.take()); grace period 5s→3sforward_loopEOF handler — 2-signal interrupt pattern with abort fallback for clean child-side shutdownkill_on_drop(true)on all shell commands (exec_command,exec_background,exec_command_streaming)Test plan
Transport::close()for stdio (4), tcp (3), duplex (4), forward_loop EOF integration (1)bazel test //...— 48/48 passbazel build //... --config=clippy— zero warnings