fix: stop idle MCP input on cancellation - #104
Open
DivyamTalwar wants to merge 1 commit into
Open
DivyamTalwar wants to merge 1 commit into
DivyamTalwar wants to merge 1 commit into
Conversation
The signal context canceled while an idle inherited stdin read remained blocked. Use a command-owned wake pipe and poll on supported Unix hosts, preserving borrowed stdin and joining cancellation cleanup. Check cancellation before reads and dispatch without reverting response-write error handling. Verification: actual main regression fails on current upstream; repeated process and transport tests pass under the race detector. Affected package race suites pass. No dependencies, SQL or JSON fields change. Opaque non-closeable readers still require caller cooperation; Windows signal runtime behavior is not claimed.
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.
What and why
Closes #103.
An idle MCP subprocess could ignore SIGINT/SIGTERM while stdin remained open: the signal context canceled, but the protocol loop stayed blocked in its read. Make inherited stdin interruptible on Linux and macOS with a command-owned wake pipe and poll. Preserve borrowed stdin, stop or join cancellation cleanup, and check cancellation before reading or dispatching another request.
The existing response-write failure handling is retained. No per-read goroutine, global stdin replacement, dependency, SQL or JSON change is introduced.
Verification
Verified commit:
fb733cd82fdc79ba8bf2b53401ee7eea72986270.9e41414abed05f10ad7ff2fbe7662a5172f151f7runs the actual main/Cobra child, waits for readiness, sends SIGTERM with stdin held open, and fails until cancellation unblocks the input.bash scripts/gate.shpasses on committed HEAD: build, vet, pinned lint, tests and all six release-platform builds.go test -race ./...passes; formatting andgit diff --checkare clean.Scope, risk and rollback
Runtime signal coverage is POSIX-specific; Windows compilation passes, but Windows signal behavior is not claimed verified. Generic opaque non-closeable readers must still cooperate to unblock a read. This fixes the actual CLI stdin path and leaves ordinary tool behavior unchanged. The public generic loop documents its cancellation boundary. Revert this commit to restore the previous input lifecycle.
Checklist