René's URL Explorer Experiment


Title: Bug: anyio.Lock in async_auth_flow causes RuntimeError under concurrent OAuth MCP connections · Issue #2847 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Bug: anyio.Lock in async_auth_flow causes RuntimeError under concurrent OAuth MCP connections · Issue #2847 · modelcontextprotocol/python-sdk

X Title: Bug: anyio.Lock in async_auth_flow causes RuntimeError under concurrent OAuth MCP connections · Issue #2847 · modelcontextprotocol/python-sdk

Description: Summary Confirmed production occurrence of the bug described in #2644 (self-closed by the original reporter before they could follow through). Filing to provide a second validated repro and draw attention to the existing draft fix in #26...

Open Graph Description: Summary Confirmed production occurrence of the bug described in #2644 (self-closed by the original reporter before they could follow through). Filing to provide a second validated repro and draw at...

X Description: Summary Confirmed production occurrence of the bug described in #2644 (self-closed by the original reporter before they could follow through). Filing to provide a second validated repro and draw at...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: anyio.Lock in async_auth_flow causes RuntimeError under concurrent OAuth MCP connections","articleBody":"## Summary\n\nConfirmed production occurrence of the bug described in #2644 (self-closed by the original reporter before they could follow through). Filing to provide a second validated repro and draw attention to the existing draft fix in #2660.\n\n## Environment\n\n- `mcp==1.26.0`\n- `anyio==4.13.0`\n- `httpx==0.28.1`\n- Python 3.11.14, macOS\n\n## What happens\n\nWhen a gateway session starts and connects to multiple OAuth-authenticated MCP servers concurrently (Notion + TinyFish, both OAuth 2.1 PKCE), Notion fails intermittently:\n\n```\nERROR asyncio: Task exception was never retrieved\nRuntimeError: The current task is not holding this lock\n  File \".../mcp/client/auth/oauth2.py\", line 503, in async_auth_flow\n  File \".../mcp/client/auth/oauth2.py\", line 484, in async_auth_flow\n    raise RuntimeError(\"The current task is not holding this lock\")\n\nWARNING tools.mcp_tool: MCP server 'notion' connection lost (attempt 1/5), reconnecting in 1s\nWARNING tools.mcp_tool: Failed to connect to MCP server 'notion': CancelledError\nINFO tools.mcp_tool: MCP: registered 114 tool(s) from 4 server(s) (1 failed)\n```\n\nNotion is affected more often than TinyFish because its OAuth token refreshes frequently (~every 15–60 min), consistently triggering the refresh `yield` path in `async_auth_flow`. TinyFish tokens expire less often and typically take the happy path (add header, yield once).\n\n## Root cause\n\n`OAuthContext.lock` is `anyio.Lock`, which records task identity at `acquire()` and enforces same-task `release()`. `async_auth_flow` is an async generator that holds this lock across `yield` points. When httpx drives the generator from a different task during concurrent connections, `anyio.Lock.release()` throws.\n\n## Existing draft fix\n\nPR #2660 addresses this correctly by narrowing lock scope so no lock is held across yields — GET SSE long-polls and token refresh yields both run outside any lock. It has full test coverage (100% on `oauth2.py`, 1177 passed) and no breaking changes, but has been sitting as a draft without maintainer review since May 22.\n\n## Workaround applied locally\n\nReplacing `anyio.Lock` with `asyncio.Lock` in `OAuthContext` stops the error since `asyncio.Lock` does not enforce task identity on release. This is a bandaid — it loses trio portability — but unblocks asyncio deployments. Note: this is a mechanical fix and has not been load-tested to exhaustion; the intermittent nature of the bug means full verification requires sustained concurrent load.\n\n## Request\n\nCould a maintainer review and merge PR #2660? The fix is principled and well-tested.","author":{"url":"https://github.com/EnGassa","@type":"Person","name":"EnGassa"},"datePublished":"2026-06-12T10:39:59Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/2847"}

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:90dfc920-85ea-54e3-b017-17d81076afb4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA4F2:2BE220:126A1E0:189EA65:6B01239F
html-safe-nonce6a490623a5d30164bdfcbf755b9f1cc0d4ad53b37ebb6c20597d7b163c0e4796
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEYyOjJCRTIyMDoxMjZBMUUwOjE4OUVBNjU6NkIwMTIzOUYiLCJ2aXNpdG9yX2lkIjoiNzA2NTY3OTkyMjM3OTU4MDQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac2a7d26bd93c6f846e0706542e9a2c3227b1b5509336895b2b7df8071f0668904
hovercard-subject-tagissue:4648518240
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/2847/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7913069bcbacceb6e3a676eeaa43a276951d9c0c9d8143cdbacd75173a5b0d0c/modelcontextprotocol/python-sdk/issues/2847
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7913069bcbacceb6e3a676eeaa43a276951d9c0c9d8143cdbacd75173a5b0d0c/modelcontextprotocol/python-sdk/issues/2847
og:image:altSummary Confirmed production occurrence of the bug described in #2644 (self-closed by the original reporter before they could follow through). Filing to provide a second validated repro and draw at...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEnGassa
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/2847#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2847
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%2F2847
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/2847
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2847
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2847
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues310 (310)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/2847
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2847
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
Bug: anyio.Lock in async_auth_flow causes RuntimeError under concurrent OAuth MCP connectionshttps://github.com/modelcontextprotocol/python-sdk/issues/2847#top
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
authIssues and PRs related to Authentication / OAuthhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22auth%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
needs confirmationNeeds confirmation that the PR is actually required or needed.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22needs%20confirmation%22
https://github.com/EnGassa
EnGassahttps://github.com/EnGassa
on Jun 12, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issue-4648518240
#2644https://github.com/modelcontextprotocol/python-sdk/issues/2644
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
https://github.com/Bartok9
Bartok9https://github.com/Bartok9
on Jun 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-4697697052
#2644https://github.com/modelcontextprotocol/python-sdk/issues/2644
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Jun 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-4698736513
https://github.com/Bartok9
Bartok9https://github.com/Bartok9
on Jun 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-4698765581
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
@peisukehttps://github.com/peisuke
#2660https://github.com/modelcontextprotocol/python-sdk/pull/2660
@peisukehttps://github.com/peisuke
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Jun 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-4698884918
https://github.com/Bartok9
Bartok9https://github.com/Bartok9
on Jun 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-4699024519
@Ben-Homehttps://github.com/Ben-Home
#2859https://github.com/modelcontextprotocol/python-sdk/pull/2859
#3https://github.com/modelcontextprotocol/python-sdk/issues/3
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
#2https://github.com/modelcontextprotocol/python-sdk/issues/2
#2859https://github.com/modelcontextprotocol/python-sdk/pull/2859
#2859https://github.com/modelcontextprotocol/python-sdk/pull/2859
Bartok9https://github.com/Bartok9
on Jun 21, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#event-27004382018
fix(oauth): narrow async_auth_flow lock scope to avoid blocking long-…https://github.com/Bartok9/python-sdk/commit/425161d4b4bc822fcf4d224c41be0a172a940d12
https://docs.github.com/articles/closing-issues-via-commit-messages
425161dhttps://github.com/Bartok9/python-sdk/commit/425161d4b4bc822fcf4d224c41be0a172a940d12
fix(oauth): narrow async_auth_flow lock scope to avoid blocking long-…https://github.com/Bartok9/python-sdk/commit/a9be0b9f359c243d380628eb30369ceb2f42f18a
https://docs.github.com/articles/closing-issues-via-commit-messages
a9be0b9https://github.com/Bartok9/python-sdk/commit/a9be0b9f359c243d380628eb30369ceb2f42f18a
https://github.com/diaanhw
diaanhwhttps://github.com/diaanhw
on Jul 8, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-4912677361
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
maxisbeyhttps://github.com/maxisbey
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
needs confirmationNeeds confirmation that the PR is actually required or needed.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22needs%20confirmation%22
authIssues and PRs related to Authentication / OAuthhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22auth%22
on Aug 14, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#event-29453866548
https://github.com/miggitty
miggittyhttps://github.com/miggitty
on Sep 3, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-5518374147
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
https://github.com/AkshayShah03
AkshayShah03https://github.com/AkshayShah03
on Oct 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2847#issuecomment-6157204715
754254chttps://github.com/modelcontextprotocol/python-sdk/commit/754254c08fe1c3eda18b69da3d336106fe8d72d6
#2858https://github.com/modelcontextprotocol/python-sdk/pull/2858
https://gist.github.com/AkshayShah03/3cea1dead96b4792a7c3e4d2d71cd7f7https://gist.github.com/AkshayShah03/3cea1dead96b4792a7c3e4d2d71cd7f7
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2847
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2847
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
authIssues and PRs related to Authentication / OAuthhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22auth%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
needs confirmationNeeds confirmation that the PR is actually required or needed.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22needs%20confirmation%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.