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
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,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-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:9f2c8f55-44a1-d4ed-37fc-d31e65038ea8 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9FF2:5FDBE:15858B:1BB225:6AFE44BC |
| html-safe-nonce | fd5423566ebec398edbaac4817c9ca6e8ee0ded4efcffac371e8256d4384f5ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkYyOjVGREJFOjE1ODU4QjoxQkIyMjU6NkFGRTQ0QkMiLCJ2aXNpdG9yX2lkIjoiNzE2NzIwNjM0NDYxOTg2OTM3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 99f79978998ca4f090ccf4c8910dc7a142d2f95f59cfdec10d66e2d52953edf1 |
| hovercard-subject-tag | pull_request:4139748745 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/microsoft/durabletask-python/pull/198/files |
| twitter:image | https://avatars.githubusercontent.com/u/4535280?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4535280?s=400&v=4 |
| og:image:alt | Summary AsyncAccessTokenManager.get_access_token() checked expiry and awaited refresh_token() with no synchronization. Because DTSAsyncDefaultClientInterceptorImpl._intercept_call() awaits it on ev... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1a5901e2377b0af2a0b303f9528678f1475d04b9219dca1e993344196eaa07c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/microsoft/durabletask-python git https://github.com/microsoft/durabletask-python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 627664515 |
| octolytics-dimension-repository_nwo | microsoft/durabletask-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627664515 |
| octolytics-dimension-repository_network_root_nwo | microsoft/durabletask-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ce393ea11ad276623b946bc9663d3e7d6f564275 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width