René's URL Explorer Experiment


Title: Bug: OAuth provider holds context.lock for the whole request, so the standalone GET SSE stream stalls the first tools/call by ~15s · Issue #3209 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Bug: OAuth provider holds context.lock for the whole request, so the standalone GET SSE stream stalls the first tools/call by ~15s · Issue #3209 · modelcontextprotocol/python-sdk

X Title: Bug: OAuth provider holds context.lock for the whole request, so the standalone GET SSE stream stalls the first tools/call by ~15s · Issue #3209 · modelcontextprotocol/python-sdk

Description: Summary With auth=OAuthClientProvider on a streamable-HTTP connection, the first tools/call of every session blocks for ~15 s. No error, no warning — just latency. Nothing is concurrent here: one server, one client, one session, sequenti...

Open Graph Description: Summary With auth=OAuthClientProvider on a streamable-HTTP connection, the first tools/call of every session blocks for ~15 s. No error, no warning — just latency. Nothing is concurrent here: one s...

X Description: Summary With auth=OAuthClientProvider on a streamable-HTTP connection, the first tools/call of every session blocks for ~15 s. No error, no warning — just latency. Nothing is concurrent here: one s...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: OAuth provider holds context.lock for the whole request, so the standalone GET SSE stream stalls the first tools/call by ~15s","articleBody":"## Summary\n\nWith `auth=OAuthClientProvider` on a **streamable-HTTP** connection, the *first* `tools/call` of every session blocks for ~15 s. No error, no warning — just latency. Nothing is concurrent here: one server, one client, one session, sequential calls.\n\nRoot cause is the same `context.lock`-held-across-`yield` problem as #2847 / #2644, but the symptom is different enough that it seems worth recording separately: #2847 is about `RuntimeError: The current task is not holding this lock` under *concurrent* OAuth connections, while this is a silent latency tax paid by *every* OAuth streamable-HTTP user, concurrency or not. Both are fixed by #2858.\n\n## Environment\n\n- `mcp==1.29.0`, `anyio==4.13.0`, `httpx==0.28.1`\n- Python 3.14.6, macOS arm64\n- Server: FastMCP behind Google Cloud Run, streamable HTTP, OAuth 2.1 + PKCE\n\n## Measurement\n\nSame server, same tool, one fresh session per call, three calls per arm. The *only* variable is how the bearer token reaches the request:\n\n```\nauth=OAuthClientProvider   : 15.68s / 15.74s / 15.80s\nstatic Authorization header:  0.70s /  0.62s /  0.67s\n```\n\nRaw HTTP JSON-RPC against the same endpoint (no SDK) answers the same tool in ~0.07 s, so the useful work is ~100 ms and effectively all of the 15.7 s is the wait.\n\nRepro:\n\n```python\nimport time, anyio\nfrom mcp.client.session import ClientSession\nfrom mcp.client.streamable_http import streamablehttp_client\n\nasync def one(*, use_provider: bool) -> float:\n    headers = None if use_provider else {\"Authorization\": f\"Bearer {ACCESS_TOKEN}\"}\n    auth = build_provider() if use_provider else None   # OAuthClientProvider\n    t0 = time.perf_counter()\n    async with streamablehttp_client(URL, headers=headers, auth=auth) as (r, w, _):\n        async with ClientSession(r, w) as session:\n            await session.initialize()\n            await session.call_tool(\"get_last_modified\", {})\n    return time.perf_counter() - t0\n```\n\n## Why it happens\n\n1. `async_auth_flow` takes `context.lock` and holds it for the whole lifetime of the request, not just while it obtains a token — the `async with self.context.lock:` at `src/mcp/client/auth/oauth2.py:492` wraps `response = yield request`.\n2. After `initialized`, `streamablehttp_client` opens the long-lived standalone GET SSE stream.\n3. That GET goes through `async_auth_flow`, takes the lock, and does not release it until the stream ends — 15–60 s in our logs, dictated by the server's/proxy's idle timeout, not by the client.\n4. The first `tools/call` therefore waits on the lock for as long as the GET stream lives.\n5. Once the stream closes, subsequent calls run at ~100 ms until the next stream is opened.\n\nSo the stall is not a fixed 15 s: it is \"however long the server keeps an idle SSE stream open\", which for Cloud Run happens to be ~15 s and for other deployments in this thread ~60 s.\n\n## The fix\n\n#2858 (rebase of #2660 by @peisuke) already does the right thing: no HTTP `yield` — including the standalone GET SSE long-poll — runs while `context.lock` is held. Verified locally that with the lock out of the request path the same call is ~0.4–0.7 s.\n\nOur workaround in the meantime is to keep `OAuthClientProvider` out of the request path entirely: read the token from storage and pass it as a plain `Authorization` header, refreshing it ourselves. That is a fine escape hatch for an application, but it means giving up the SDK's auth handling, which most users reasonably will not want to do.\n\nWould a maintainer be able to look at #2858? It fixes a correctness bug for concurrent users and a ~15 s per-session latency bug for everyone else.\n","author":{"url":"https://github.com/stayclosetothequestion","@type":"Person","name":"stayclosetothequestion"},"datePublished":"2026-07-29T11:34:38Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3209"}

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:e714e37d-e82a-05ae-f04f-671e1ec53b77
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id987C:21E3E7:1612C7E:1D15874:6B012E57
html-safe-noncea7b51cdd5b2d4ecf0b56e3d802226f4988bcfbcac1f97ac10d6843e3b548ba29
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODdDOjIxRTNFNzoxNjEyQzdFOjFEMTU4NzQ6NkIwMTJFNTciLCJ2aXNpdG9yX2lkIjoiNjE1MTAwNTYyMzQxMzcxNDUxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccc6700cc3cf801a01d2e0f439e8ac2704dc51c7ad72d9f20fd76fb997c1c7db2
hovercard-subject-tagissue:5008752248
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/3209/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1a3a471c471289af04f51f9394315c636a01455a3c0b06e66f306fe064bfe8a9/modelcontextprotocol/python-sdk/issues/3209
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1a3a471c471289af04f51f9394315c636a01455a3c0b06e66f306fe064bfe8a9/modelcontextprotocol/python-sdk/issues/3209
og:image:altSummary With auth=OAuthClientProvider on a streamable-HTTP connection, the first tools/call of every session blocks for ~15 s. No error, no warning — just latency. Nothing is concurrent here: one s...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamestayclosetothequestion
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3209#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3209
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%2F3209
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/3209
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3209
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3209
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues315 (315)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/3209
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3209
Bug: OAuth provider holds context.lock for the whole request, so the standalone GET SSE stream stalls the first tools/call by ~15shttps://github.com/modelcontextprotocol/python-sdk/issues/3209#top
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
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/stayclosetothequestion
stayclosetothequestionhttps://github.com/stayclosetothequestion
on Jul 29, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3209#issue-5008752248
#2847https://github.com/modelcontextprotocol/python-sdk/issues/2847
#2644https://github.com/modelcontextprotocol/python-sdk/issues/2644
#2847https://github.com/modelcontextprotocol/python-sdk/issues/2847
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
@peisukehttps://github.com/peisuke
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Jul 29, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3209#issuecomment-5118874422
https://github.com/Ecocitizenz
Ecocitizenzhttps://github.com/Ecocitizenz
on Jul 31, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3209#issuecomment-5138370368
maxisbeyhttps://github.com/maxisbey
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%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
on Aug 12, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3209#event-29354928845
claudehttps://github.com/apps/claude
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
on Oct 8, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3209#event-32781072247
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3209
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3209
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
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

Viewport: width=device-width


URLs of crawlers that visited me.