René's URL Explorer Experiment


Title: Performance [P1]: Single-flight async Azure token refresh by berndverst · Pull Request #198 · microsoft/durabletask-python · GitHub

Open Graph Title: Performance [P1]: Single-flight async Azure token refresh by berndverst · Pull Request #198 · microsoft/durabletask-python

X Title: Performance [P1]: Single-flight async Azure token refresh by berndverst · Pull Request #198 · microsoft/durabletask-python

Description: Summary AsyncAccessTokenManager.get_access_token() checked expiry and awaited refresh_token() with no synchronization. Because DTSAsyncDefaultClientInterceptorImpl._intercept_call() awaits it on every RPC, a burst of concurrent grpc.aio calls arriving while the token was missing or inside its renewal window would each independently hit the credential — a thundering herd of Entra/credential requests, added latency, and avoidable throttling pressure. The synchronous AccessTokenManager already guards this with double-checked locking; the async path did not. This change mirrors that design for the async manager: get_access_token() now re-checks token validity after acquiring a refresh guard, so only one coroutine calls the credential per refresh window and the rest reuse the result. The guard is an asyncio.Lock created lazily per running event loop (kept in a small map guarded by a threading.Lock). An asyncio.Lock binds itself to the loop it is first awaited on, so a single lock created in __init__ would raise if the manager outlived a loop or was shared across loops. Locks belonging to closed loops are pruned so the map cannot grow without bound. The fast path is unchanged: when a cached token is still valid, the outer check short-circuits and no lock is touched, so there is no added per-RPC overhead. Failures propagate unchanged — the guard is released via async with, so a credential error surfaces to the caller and a later attempt can still succeed. Backwards compatibility No public API changes. Method signatures, return values, the expiry/renewal margin behavior, exception propagation, logging, and sync-path thread-safety are all preserved. The only new members are private (_get_refresh_lock, _refresh_locks, _refresh_locks_guard). Scope Deliberately narrow, limited to this issue. It does not touch deferred sync token acquisition (#187) or SDK version lookup caching (#195), which are being addressed separately in these same files. Verification New tests in tests/durabletask-azuremanaged/test_durabletask_grpc_interceptor.py, modeled on the existing sync test_concurrent_refresh_performs_single_refresh: 16 concurrent cold-start callers result in exactly 1 credential call. 16 concurrent callers after expiry result in exactly 1 refresh. A valid cached token is returned without contacting the credential. A credential failure propagates to waiters and does not deadlock; a subsequent attempt succeeds. The manager is reusable across two distinct event loops (guards against binding the lock to a dead loop). Confirmed the tests catch the bug: with the source change reverted, the two single-flight tests fail with 1 != 16 and 2 != 17 — exactly the duplicate acquisition described in the issue. Provider unit tests: test_durabletask_grpc_interceptor.py + test_sandboxes_extension.py — 47 passed (42 at baseline, +5 new). Core unit tests: tests/durabletask excluding *_e2e.py — 681 passed, 7 skipped, identical to baseline. flake8 clean on both changed Python files; pyright reports 0 errors on the changed source; pymarkdown introduces no new findings (the two MD013 hits on the changelog are pre-existing lines). test_dts_batch_actions.py fails identically with and without this change (11 failures on a clean baseline); it requires a live Durable Task Scheduler endpoint. Fixes #192

Open Graph Description: Summary AsyncAccessTokenManager.get_access_token() checked expiry and awaited refresh_token() with no synchronization. Because DTSAsyncDefaultClientInterceptorImpl._intercept_call() awaits it on ev...

X Description: Summary AsyncAccessTokenManager.get_access_token() checked expiry and awaited refresh_token() with no synchronization. Because DTSAsyncDefaultClientInterceptorImpl._intercept_call() awaits it on ev...

Opengraph URL: https://github.com/microsoft/durabletask-python/pull/198

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:9f2c8f55-44a1-d4ed-37fc-d31e65038ea8
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9FF2:5FDBE:15858B:1BB225:6AFE44BC
html-safe-noncefd5423566ebec398edbaac4817c9ca6e8ee0ded4efcffac371e8256d4384f5ab
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkYyOjVGREJFOjE1ODU4QjoxQkIyMjU6NkFGRTQ0QkMiLCJ2aXNpdG9yX2lkIjoiNzE2NzIwNjM0NDYxOTg2OTM3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac99f79978998ca4f090ccf4c8910dc7a142d2f95f59cfdec10d66e2d52953edf1
hovercard-subject-tagpull_request:4139748745
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/microsoft/durabletask-python/pull/198/files
twitter:imagehttps://avatars.githubusercontent.com/u/4535280?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4535280?s=400&v=4
og:image:altSummary AsyncAccessTokenManager.get_access_token() checked expiry and awaited refresh_token() with no synchronization. Because DTSAsyncDefaultClientInterceptorImpl._intercept_call() awaits it on ev...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonef1a5901e2377b0af2a0b303f9528678f1475d04b9219dca1e993344196eaa07c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/microsoft/durabletask-python git https://github.com/microsoft/durabletask-python.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id627664515
octolytics-dimension-repository_nwomicrosoft/durabletask-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id627664515
octolytics-dimension-repository_network_root_nwomicrosoft/durabletask-python
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasece393ea11ad276623b946bc9663d3e7d6f564275
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/microsoft/durabletask-python/pull/198/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fdurabletask-python%2Fpull%2F198%2Ffiles
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%2Fmicrosoft%2Fdurabletask-python%2Fpull%2F198%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=microsoft%2Fdurabletask-python
Reloadhttps://github.com/microsoft/durabletask-python/pull/198/files
Reloadhttps://github.com/microsoft/durabletask-python/pull/198/files
Reloadhttps://github.com/microsoft/durabletask-python/pull/198/files
microsofthttps://github.com/microsoft
durabletask-pythonhttps://github.com/microsoft/durabletask-python
Codehttps://github.com/microsoft/durabletask-python
Issues15 (15)https://github.com/microsoft/durabletask-python/issues
Pull requests12 (12)https://github.com/microsoft/durabletask-python/pulls
Actionshttps://github.com/microsoft/durabletask-python/actions
Projectshttps://github.com/microsoft/durabletask-python/projects
Security and qualityhttps://github.com/microsoft/durabletask-python/security
Insightshttps://github.com/microsoft/durabletask-python/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fmicrosoft%2Fdurabletask-python%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmicrosoft%2Fdurabletask-python%2Fissues%2Fnew%2Fchoose
Bernd Verst (berndverst)https://github.com/berndverst
mainhttps://github.com/microsoft/durabletask-python/tree/main
berndverst-single-flight-async-token-refreshhttps://github.com/microsoft/durabletask-python/tree/berndverst-single-flight-async-token-refresh
Conversation 5 https://github.com/microsoft/durabletask-python/pull/198
Commits 3 https://github.com/microsoft/durabletask-python/pull/198/commits
Checks 24 https://github.com/microsoft/durabletask-python/pull/198/checks
Files changed https://github.com/microsoft/durabletask-python/pull/198/files
Please reload this pagehttps://github.com/microsoft/durabletask-python/pull/198/files
Performance [P1]: Single-flight async Azure token refresh https://github.com/microsoft/durabletask-python/pull/198/files#top
Show all changes 3 commits https://github.com/microsoft/durabletask-python/pull/198/files
5f433de perf: single-flight async Azure token refresh Jul 27, 2026 https://github.com/microsoft/durabletask-python/pull/198/commits/5f433de385e4b6a6e079b72af938f8edb9dd9035
76e8f0a Merge remote-tracking branch 'origin/main' into berndverst-single-fli… Jul 27, 2026 https://github.com/microsoft/durabletask-python/pull/198/commits/76e8f0a4ade12f312b711fd004cef89a292596f4
4b3bbb2 refactor: hoist stale-loop comprehension into a named local Jul 27, 2026 https://github.com/microsoft/durabletask-python/pull/198/commits/4b3bbb2219d83ab7a47b3e02f0536a833d53d89a
Clear filters https://github.com/microsoft/durabletask-python/pull/198/files
Please reload this pagehttps://github.com/microsoft/durabletask-python/pull/198/files
Please reload this pagehttps://github.com/microsoft/durabletask-python/pull/198/files
CHANGELOG.md https://github.com/microsoft/durabletask-python/pull/198/files#diff-1d1ece375471f083a849ea1b601985661b8bd8e7017fdb7fd5d10e02c4ca69f6
access_token_manager.py https://github.com/microsoft/durabletask-python/pull/198/files#diff-4c5045747bb8155edc42b000ebe6910fdbc6f40bf200fd07a6734d0efb646d42
test_durabletask_grpc_interceptor.py https://github.com/microsoft/durabletask-python/pull/198/files#diff-8ca4e0ba6893c08e8500e9262abe4a4c6c927c0fdebb06acf2d3a7e374ce1e2a
durabletask-azuremanaged/CHANGELOG.mdhttps://github.com/microsoft/durabletask-python/pull/198/files#diff-1d1ece375471f083a849ea1b601985661b8bd8e7017fdb7fd5d10e02c4ca69f6
View file https://github.com/microsoft/durabletask-python/blob/4b3bbb2219d83ab7a47b3e02f0536a833d53d89a/durabletask-azuremanaged/CHANGELOG.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/microsoft/durabletask-python/pull/198/{{ revealButtonHref }}
https://github.com/microsoft/durabletask-python/pull/198/files#diff-1d1ece375471f083a849ea1b601985661b8bd8e7017fdb7fd5d10e02c4ca69f6
https://github.com/microsoft/durabletask-python/pull/198/files#diff-1d1ece375471f083a849ea1b601985661b8bd8e7017fdb7fd5d10e02c4ca69f6
durabletask-azuremanaged/durabletask/azuremanaged/internal/access_token_manager.pyhttps://github.com/microsoft/durabletask-python/pull/198/files#diff-4c5045747bb8155edc42b000ebe6910fdbc6f40bf200fd07a6734d0efb646d42
View file https://github.com/microsoft/durabletask-python/blob/4b3bbb2219d83ab7a47b3e02f0536a833d53d89a/durabletask-azuremanaged/durabletask/azuremanaged/internal/access_token_manager.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/microsoft/durabletask-python/pull/198/{{ revealButtonHref }}
Please reload this pagehttps://github.com/microsoft/durabletask-python/pull/198/files
https://github.com/microsoft/durabletask-python/pull/198/files#diff-4c5045747bb8155edc42b000ebe6910fdbc6f40bf200fd07a6734d0efb646d42
https://github.com/microsoft/durabletask-python/pull/198/files#diff-4c5045747bb8155edc42b000ebe6910fdbc6f40bf200fd07a6734d0efb646d42
https://github.com/microsoft/durabletask-python/pull/198/files#diff-4c5045747bb8155edc42b000ebe6910fdbc6f40bf200fd07a6734d0efb646d42
tests/durabletask-azuremanaged/test_durabletask_grpc_interceptor.pyhttps://github.com/microsoft/durabletask-python/pull/198/files#diff-8ca4e0ba6893c08e8500e9262abe4a4c6c927c0fdebb06acf2d3a7e374ce1e2a
View file https://github.com/microsoft/durabletask-python/blob/4b3bbb2219d83ab7a47b3e02f0536a833d53d89a/tests/durabletask-azuremanaged/test_durabletask_grpc_interceptor.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/microsoft/durabletask-python/pull/198/{{ revealButtonHref }}
https://github.com/microsoft/durabletask-python/pull/198/files#diff-8ca4e0ba6893c08e8500e9262abe4a4c6c927c0fdebb06acf2d3a7e374ce1e2a
https://github.com/microsoft/durabletask-python/pull/198/files#diff-8ca4e0ba6893c08e8500e9262abe4a4c6c927c0fdebb06acf2d3a7e374ce1e2a
https://github.com/microsoft/durabletask-python/pull/198/files#diff-8ca4e0ba6893c08e8500e9262abe4a4c6c927c0fdebb06acf2d3a7e374ce1e2a
Please reload this pagehttps://github.com/microsoft/durabletask-python/pull/198/files
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.