Title: Performance [P2]: Reuse sandbox registration transport on retries by berndverst · Pull Request #206 · microsoft/durabletask-python · GitHub
Open Graph Title: Performance [P2]: Reuse sandbox registration transport on retries by berndverst · Pull Request #206 · microsoft/durabletask-python
X Title: Performance [P2]: Reuse sandbox registration transport on retries by berndverst · Pull Request #206 · microsoft/durabletask-python
Description: Summary SandboxWorker._run_sandbox_registration_loop() constructed a brand new SandboxActivitiesGrpcTransport on every retry attempt. Each construction created a new gRPC channel, a new stub, and a new DTSDefaultClientInterceptorImpl, which in turn acquires an Entra token in its constructor. A transient registration failure therefore cost a full channel setup plus a token acquisition per retry, amplifying startup and recovery latency exactly when the service was already degraded. The registration loop now builds the transport once and reuses it across retriable stream failures, closing it once when the loop exits so channels are not leaked. What changed durabletask-azuremanaged/durabletask/azuremanaged/preview/sandboxes/worker.py The transport is created lazily on the first attempt and reused for subsequent attempts, including the reconnect path where the server ends the registration stream while the worker is still running. Added _requires_new_registration_transport(), which replaces the transport only when a failure leaves the channel unusable: a channel that has been shut down (CANCELLED with Channel closed!) or any non-gRPC failure, such as an error raised while the channel itself is being created. gRPC channels reconnect on their own after transient RPC failures, so those reuse the existing transport. Added _close_sandbox_registration_transport(), which closes the transport defensively and is invoked from a finally block covering the whole loop. Everything else is unchanged: the exponential backoff schedule, responsiveness to the stop signal, thread join semantics, log messages, and the exception types and terminal handling for non-retriable failures. No public API, signature, import path, or observable behavior changes, so per the repository changelog policy this internal performance fix does not get a changelog entry. Verification New tests in tests/durabletask-azuremanaged/test_sandboxes_extension.py: test_sandbox_registration_reuses_one_transport_across_retriable_failures uses a fake transport factory to assert that 3 retriable UNAVAILABLE failures result in exactly 1 transport construction and 1 close, and that the backoff windows are still 1.0, 2.0, 4.0. test_sandbox_registration_rebuilds_transport_after_channel_shutdown asserts a shut-down channel still produces a replacement transport, and that the discarded transport is closed. test_sandbox_registration_loop_exits_promptly_on_stop_signal runs the loop on a thread and asserts it exits promptly once the stop event is set, with the transport closed exactly once. test_sandbox_registration_recreates_transport_only_when_channel_is_unusable covers the reuse-versus-replace predicate directly. The reuse test fails against the pre-fix implementation (4 transports instead of 1), confirming it guards the regression. pytest tests/durabletask-azuremanaged/test_sandboxes_extension.py tests/durabletask-azuremanaged/test_durabletask_grpc_interceptor.py -q -> 46 passed (42 before, plus the 4 new tests). pytest tests/durabletask -q --ignore-glob="*_e2e.py" -> 681 passed, 7 skipped. flake8 clean on both changed files. pyright reports 0 errors for the changed source file under the repository's strict configuration. Out of scope The issue's cold-start note about sharing channel or authentication state with the parent DurableTaskSchedulerWorker is intentionally not addressed here; it overlaps with the deferred token acquisition work tracked in #187. Fixes #188
Open Graph Description: Summary SandboxWorker._run_sandbox_registration_loop() constructed a brand new SandboxActivitiesGrpcTransport on every retry attempt. Each construction created a new gRPC channel, a new stub, and a...
X Description: Summary SandboxWorker._run_sandbox_registration_loop() constructed a brand new SandboxActivitiesGrpcTransport on every retry attempt. Each construction created a new gRPC channel, a new stub, and a...
Opengraph URL: https://github.com/microsoft/durabletask-python/pull/206
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:b6718c9d-0af9-8b21-56cc-fc6f05b5e2ea |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 83BE:22A512:D73CA:120F62:6AFE44BA |
| html-safe-nonce | 407374f78b12d6bfd0d7fa6ecdbb435ae4086224eba752512742b6736d14607e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0JFOjIyQTUxMjpENzNDQToxMjBGNjI6NkFGRTQ0QkEiLCJ2aXNpdG9yX2lkIjoiNTY3ODkyMzA3MzMwMjk3MTU3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0f13328935f237faf3b18e49a1314c8add3e178b8fb62e8f1049204ac299fe3c |
| hovercard-subject-tag | pull_request:4139791292 |
| 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/206/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 SandboxWorker._run_sandbox_registration_loop() constructed a brand new SandboxActivitiesGrpcTransport on every retry attempt. Each construction created a new gRPC channel, a new stub, and a... |
| 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