René's URL Explorer Experiment


Title: stdio server never exits on stdin EOF while the client leaves stdout unread · Issue #3674 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: stdio server never exits on stdin EOF while the client leaves stdout unread · Issue #3674 · modelcontextprotocol/python-sdk

X Title: stdio server never exits on stdin EOF while the client leaves stdout unread · Issue #3674 · modelcontextprotocol/python-sdk

Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before openi...

Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...

X Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/mod...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3674

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"stdio server never exits on stdin EOF while the client leaves stdout unread","articleBody":"### Initial Checks\n- [X] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)\n- [X] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Release line\n\n2.x (current stable)\n\n### Description\n\nWhen a stdio client closes the server's stdin while a response is still being written to a full, unread stdout pipe, `MCPServer.run()` never returns. The process sits idle until it is signalled.\n\nSteps: the client sends a request whose response is larger than the pipe buffer, does not read stdout, then closes stdin. The server keeps running indefinitely. If the client drains stdout, the same sequence exits 0 right away.\n\nThread dump of the hung server (faulthandler): the main thread is idle in the event loop's `select`, and one AnyIO worker thread is inside `context.run(func, *args)`, blocked in the C-level `write(2)` behind `stdout_writer`'s `await stdout.write(...)` / `await stdout.flush()` in `mcp/server/stdio.py`. `AsyncFile.write` calls `to_thread.run_sync` without `abandon_on_cancel`. So when stdin EOF ends the session and the task group cancels `stdout_writer`, the cancellation waits for a write that can only finish if the client reads. `stdio.py` already expects this case (`closefd=False`, because \"a worker thread can still block on this descriptor after the transport exits\"). The exit path still waits on that thread, though.\n\nImpact is limited for clients that follow the spec's stdio shutdown, which escalates to SIGTERM and then SIGKILL. The TypeScript SDK client does this after 2 s per step. Any client that stops at \"close stdin and wait\" will leak the server process.\n\nThis is related to #2678 but is a different bug. #2678 is about responses lost on EOF, while this one is about the process never exiting on EOF. A fix for #2678 that drains pending responses before exiting needs a bound on that drain. Otherwise it would turn every undeliverable response into this hang.\n\n### Example Code\n\n```python\n# server.py\nfrom mcp.server.mcpserver import MCPServer\n\nmcp = MCPServer(\"eof-hang-repro\")\n\n\n@mcp.tool()\ndef big() -> str:\n    \"\"\"Return a response larger than a pipe buffer.\"\"\"\n    return \"x\" * 1_000_000\n\n\nif __name__ == \"__main__\":\n    mcp.run()\n```\n\n```python\n# client.py: python client.py [--drain]\nimport json, subprocess, sys, threading, time\nfrom pathlib import Path\n\ndrain = \"--drain\" in sys.argv\nproc = subprocess.Popen([sys.executable, str(Path(__file__).with_name(\"server.py\"))],\n                        stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)\n\n\ndef send(message):\n    proc.stdin.write((json.dumps(message) + \"\\n\").encode())\n    proc.stdin.flush()\n\n\nsend({\"jsonrpc\": \"2.0\", \"id\": 0, \"method\": \"initialize\", \"params\": {\n    \"protocolVersion\": \"2025-06-18\", \"capabilities\": {},\n    \"clientInfo\": {\"name\": \"repro\", \"version\": \"0\"}}})\nproc.stdout.readline()\nsend({\"jsonrpc\": \"2.0\", \"method\": \"notifications/initialized\"})\nsend({\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"tools/call\", \"params\": {\"name\": \"big\", \"arguments\": {}}})\nif drain:\n    threading.Thread(target=proc.stdout.read, daemon=True).start()\ntime.sleep(1)\nproc.stdin.close()\ntry:\n    proc.wait(timeout=10)\n    print(f\"drain={drain}: exited {proc.returncode} after stdin EOF\")\nexcept subprocess.TimeoutExpired:\n    print(f\"drain={drain}: still running 10 s after stdin EOF\")\n    proc.terminate()\n    proc.wait()\n```\n\nOutput:\n\n```\n$ python client.py\ndrain=False: still running 10 s after stdin EOF\n$ python client.py --drain\ndrain=True: exited 0 after stdin EOF\n```\n\n`stdio.py` is the same in 2.2.0, 2.3.0 and current `main`. In the downstream project where this came up (kwin-mcp), the hang still occurs after the server's own signal handling was hardened, because it depends only on `run()` returning after EOF.\n\n### Python & MCP Python SDK\n\n```\nPython 3.14.7 (Fedora 44, Linux 7.2)\nmcp 2.3.0 (also reproduced on 2.2.0), anyio 4.15.1\n```\n\n---\n\u003csub>\u003cem>**[@superbiche](https://github.com/superbiche)** · user · drafted with Claude Opus 5.5, reviewed before posting; the voice and decisions are mine.\u003c/em>\u003c/sub>\n","author":{"url":"https://github.com/superbiche","@type":"Person","name":"superbiche"},"datePublished":"2026-10-10T20:15:58Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3674"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a513e57c-10d7-f460-bbed-3fa0e258af03
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC8E0:63337:4AE5BA:69EEA1:6B0471B2
html-safe-nonce072d20f71eb43db1eb081b5f51a7bddc176d822bf9933068f5a94e51494e3c0a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEUwOjYzMzM3OjRBRTVCQTo2OUVFQTE6NkIwNDcxQjIiLCJ2aXNpdG9yX2lkIjoiNTY2NDY3NjA5MTI1NjkyNjY0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1124571ad9dd7c1f1f6029e591e820b64301d074e268f7e006bf2dce517f6e57
hovercard-subject-tagissue:5794912900
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3674/issue_layout
twitter:imagehttps://opengraph.githubassets.com/44b19f5739ae5dcbd58be258c28749c24726c94140e2277693d17d3517d472f9/modelcontextprotocol/python-sdk/issues/3674
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/44b19f5739ae5dcbd58be258c28749c24726c94140e2277693d17d3517d472f9/modelcontextprotocol/python-sdk/issues/3674
og:image:altInitial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesuperbiche
hostnamegithub.com
expected-hostnamegithub.com
Noneae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecfb5f24c6e01d85f70804652a5107e5cac03a161
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3674#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3674
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3674
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3674
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3674
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3674
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues320 (320)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
https://github.com/modelcontextprotocol/python-sdk
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3674
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3674
stdio server never exits on stdin EOF while the client leaves stdout unreadhttps://github.com/modelcontextprotocol/python-sdk/issues/3674#top
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
https://github.com/superbiche
superbichehttps://github.com/superbiche
on Oct 10, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3674#issue-5794912900
https://github.com/modelcontextprotocol/python-sdk/issueshttps://github.com/modelcontextprotocol/python-sdk/issues
#2678https://github.com/modelcontextprotocol/python-sdk/issues/2678
#2678https://github.com/modelcontextprotocol/python-sdk/issues/2678
#2678https://github.com/modelcontextprotocol/python-sdk/issues/2678
@superbichehttps://github.com/superbiche
claudehttps://github.com/apps/claude
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
on Oct 10, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3674#event-32957442262
https://github.com/nosmile99
nosmile99https://github.com/nosmile99
on Oct 11, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3674#issuecomment-6106317987
#2678https://github.com/modelcontextprotocol/python-sdk/issues/2678
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3674
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3674
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.