René's URL Explorer Experiment


Title: Executor does not close suspended orchestrator generators when a dispatch ends · Issue #299 · microsoft/durabletask-python · GitHub

Open Graph Title: Executor does not close suspended orchestrator generators when a dispatch ends · Issue #299 · microsoft/durabletask-python

X Title: Executor does not close suspended orchestrator generators when a dispatch ends · Issue #299 · microsoft/durabletask-python

Description: _OrchestrationExecutor.execute() reconstructs a generator for each dispatch, but does not explicitly close it when execution suspends at a durable wait. That can leave an async bridge's task, event loop, and orchestration context alive a...

Open Graph Description: _OrchestrationExecutor.execute() reconstructs a generator for each dispatch, but does not explicitly close it when execution suspends at a durable wait. That can leave an async bridge's task, event...

X Description: _OrchestrationExecutor.execute() reconstructs a generator for each dispatch, but does not explicitly close it when execution suspends at a durable wait. That can leave an async bridge's task, e...

Opengraph URL: https://github.com/microsoft/durabletask-python/issues/299

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Executor does not close suspended orchestrator generators when a dispatch ends","articleBody":"`_OrchestrationExecutor.execute()` reconstructs a generator for each dispatch, but does not explicitly close it when execution suspends at a durable wait. That can leave an async bridge's task, event loop, and orchestration context alive after the dispatch has finished.\r\n\r\nThis is more than delayed collection. An open AnyIO cancel scope is reachable through AnyIO's global weak-key task-state registry, whose value refers back to the task key. Calling `gc.collect()` does not release the suspended bridge.\r\n\r\n## Reproduction\r\n\r\nThe script below uses only the native SDK executor, AnyIO, and the standard library. It creates no scheduler connection and performs no real waits. Reproduced against `cb75760` on CPython 3.12.3 with `durabletask 1.12.0` and `anyio 4.14.2`.\r\n\r\nThe bridge yields a durable timer while an async task owns an AnyIO scope:\r\n\r\n```python\r\ndef episode(context):\r\n    loop = asyncio.new_event_loop()\r\n\r\n    async def body():\r\n        assert context.instance_id == \"native-sdk-repro\"\r\n        try:\r\n            async with anyio.create_task_group():\r\n                await asyncio.Future()\r\n        finally:\r\n            await asyncio.sleep(0)\r\n            cleaned.append(\"closed\")\r\n\r\n    root = loop.create_task(body())\r\n    loop.run_until_complete(asyncio.sleep(0))\r\n    try:\r\n        yield context.create_timer(timedelta(seconds=5))\r\n    finally:\r\n        root.cancel()\r\n        loop.run_until_complete(asyncio.gather(root, return_exceptions=True))\r\n        loop.run_until_complete(loop.shutdown_asyncgens())\r\n        loop.close()\r\n```\r\n\r\nAfter calling the native executor and collecting garbage, weak references to the context, generator, loop, and task are all still live, and `cleaned` is empty. Calling `generator.close()` explicitly runs the cleanup; a second close is harmless.\r\n\r\n```console\r\n$ python repro.py\r\nVersions: durabletask 1.12.0 anyio 4.14.2\r\nAfter execute + GC: {'loop': True, 'root': True, 'context': True, 'generator': True}\r\nCleanup: []\r\nAfter explicit idempotent close: ['closed']\r\n```\r\n\r\n**Expected:** the generator's cleanup finishes before the dispatch returns.\r\n\r\n**Actual:** its async task and context can remain reachable indefinitely, leaking one episode for each replay.\r\n\r\n\u003cdetails>\r\n\u003csummary>Full standalone reproducer\u003c/summary>\r\n\r\n```python\r\nimport asyncio\r\nimport gc\r\nimport logging\r\nfrom datetime import datetime, timedelta\r\nfrom importlib.metadata import version\r\nfrom weakref import ref\r\n\r\nimport anyio\r\nfrom durabletask import worker\r\nfrom durabletask.internal import helpers, orchestrator_service_pb2 as pb\r\nfrom durabletask.serialization import DEFAULT_DATA_CONVERTER\r\n\r\n\r\ndef main():\r\n    references = {}\r\n    cleaned = []\r\n\r\n    def episode(context):\r\n        loop = asyncio.new_event_loop()\r\n\r\n        async def body():\r\n            assert context.instance_id == 'native-sdk-repro'\r\n            try:\r\n                async with anyio.create_task_group():\r\n                    await asyncio.Future()\r\n            finally:\r\n                await asyncio.sleep(0)\r\n                cleaned.append('closed')\r\n\r\n        root = loop.create_task(body())\r\n        references['loop'] = ref(loop)\r\n        references['root'] = ref(root)\r\n        loop.run_until_complete(asyncio.sleep(0))\r\n        try:\r\n            yield context.create_timer(timedelta(seconds=5))\r\n        finally:\r\n            root.cancel()\r\n            loop.run_until_complete(asyncio.gather(root, return_exceptions=True))\r\n            loop.run_until_complete(loop.shutdown_asyncgens())\r\n            loop.close()\r\n\r\n    def orchestrator(context, payload):\r\n        generator = episode(context)\r\n        references['context'] = ref(context)\r\n        references['generator'] = ref(generator)\r\n        return generator\r\n\r\n    registry_worker = worker.TaskHubGrpcWorker.__new__(worker.TaskHubGrpcWorker)\r\n    registry_worker._registry = worker._Registry()\r\n    registry_worker._is_running = False\r\n    registry_worker.add_orchestrator(orchestrator)\r\n    started = pb.HistoryEvent(orchestratorStarted=pb.OrchestratorStartedEvent())\r\n    started.timestamp.FromDatetime(datetime(2026, 1, 1))\r\n    events = [\r\n        started,\r\n        helpers.new_execution_started_event('orchestrator', 'native-sdk-repro', None),\r\n    ]\r\n    try:\r\n        worker._OrchestrationExecutor(\r\n            registry_worker._registry, logging.getLogger('sdk-repro'), data_converter=DEFAULT_DATA_CONVERTER\r\n        ).execute('native-sdk-repro', [], events)\r\n        gc.collect()\r\n        print('Versions:', 'durabletask', version('durabletask'), 'anyio', version('anyio'))\r\n        print('After execute + GC:', {key: value() is not None for key, value in references.items()})\r\n        print('Cleanup:', cleaned)\r\n        assert cleaned == []\r\n        assert all(value() is not None for value in references.values())\r\n    finally:\r\n        if (generator := references['generator']()) is not None:\r\n            generator.close()\r\n            generator.close()\r\n    print('After explicit idempotent close:', cleaned)\r\n    assert cleaned == ['closed']\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n```\r\n\r\n\u003c/details>\r\n\r\n## Suggested ownership boundary\r\n\r\nClose the generator in an executor `finally`, after all old/new events have been processed and the response has been constructed. Closing must not happen between events or allow teardown to add durable actions or change the already-decided response.\r\n\r\nLog ordinary cleanup failures with the instance and orchestration name, without replacing a dispatch result or masking version rejection. Cover suspension, completion, failure, continue-as-new, and exceptional exits, plus the AnyIO case with weak references and explicit collection.\r\n\r\nI hit this while building the Pydantic AI integration (pydantic/pydantic-ai#4764), which needs this guarantee from the SDK. The async/await work in #293 / #294 should use the same ownership boundary. I have a fix with tests ready and will open a PR referencing this issue.","author":{"url":"https://github.com/tamirdresher","@type":"Person","name":"tamirdresher"},"datePublished":"2026-10-20T11:04:21Z","url":"https://github.com/microsoft/durabletask-python/issues/299"}

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:5070995a-550f-f762-6f8f-26eea27cd28c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id85F8:3E0418:6E36C:92B27:6AFE2CAF
html-safe-nonce3cb1f477cad87d27826c04266bd0bbc88efea1e1bf39e3bcb8d6f83809512779
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUY4OjNFMDQxODo2RTM2Qzo5MkIyNzo2QUZFMkNBRiIsInZpc2l0b3JfaWQiOiIxOTUxNTMyNjczMjIyNDU0NDQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd8e4d4646b8578376c95332517f27171da1b708510fd3bf08f99064809f1601f
hovercard-subject-tagissue:5940528337
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/microsoft/durabletask-python/299/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1ec700e0bd7918603843281ef45d01b19e0fcb4b4cc6da3b500c26b297d740f1/microsoft/durabletask-python/issues/299
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1ec700e0bd7918603843281ef45d01b19e0fcb4b4cc6da3b500c26b297d740f1/microsoft/durabletask-python/issues/299
og:image:alt_OrchestrationExecutor.execute() reconstructs a generator for each dispatch, but does not explicitly close it when execution suspends at a durable wait. That can leave an async bridge's task, event...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametamirdresher
hostnamegithub.com
expected-hostnamegithub.com
Nonee973f9ec3625f3faad8cac5c2d11a214b7ffe45f3cc563b828459b290ecaeed3
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release1f92c367595b9190e0be293896078033886b1913
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/durabletask-python/issues/299#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fdurabletask-python%2Fissues%2F299
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%2Fissues%2F299
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=microsoft%2Fdurabletask-python
Reloadhttps://github.com/microsoft/durabletask-python/issues/299
Reloadhttps://github.com/microsoft/durabletask-python/issues/299
Reloadhttps://github.com/microsoft/durabletask-python/issues/299
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
https://github.com/microsoft/durabletask-python
New issuehttps://github.com/login?return_to=https://github.com/microsoft/durabletask-python/issues/299
New issuehttps://github.com/login?return_to=https://github.com/microsoft/durabletask-python/issues/299
#300https://github.com/microsoft/durabletask-python/pull/300
Executor does not close suspended orchestrator generators when a dispatch endshttps://github.com/microsoft/durabletask-python/issues/299#top
#300https://github.com/microsoft/durabletask-python/pull/300
bugSomething isn't workinghttps://github.com/microsoft/durabletask-python/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/tamirdresher
Tamir Dresher (tamirdresher)https://github.com/tamirdresher
on Oct 20, 2026https://github.com/microsoft/durabletask-python/issues/299#issue-5940528337
pydantic/pydantic-ai#4764https://github.com/pydantic/pydantic-ai/issues/4764
#293https://github.com/microsoft/durabletask-python/pull/293
#294https://github.com/microsoft/durabletask-python/issues/294
Tamir Dresher (tamirdresher)https://github.com/tamirdresher
bugSomething isn't workinghttps://github.com/microsoft/durabletask-python/issues?q=state%3Aopen%20label%3A%22bug%22
on Oct 20, 2026https://github.com/microsoft/durabletask-python/issues/299#event-33734854660
Tamir Dresher (tamirdresher)https://github.com/tamirdresher
completedhttps://github.com/microsoft/durabletask-python/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#300https://github.com/microsoft/durabletask-python/pull/300
on Oct 20, 2026https://github.com/microsoft/durabletask-python/issues/299#event-33766772638
Hardik K (hardikkaurani)https://github.com/hardikkaurani
on Oct 22, 2026https://github.com/microsoft/durabletask-python/issues/299#event-33911129467
fix(worker): close orchestrator generators when a dispatch ends (micr…https://github.com/hardikkaurani/durabletask-python/commit/4b076bacca87e7daf30d7dd7164afe2c7c7cdc31
micr…https://github.com/microsoft/durabletask-python/pull/300
https://docs.github.com/articles/closing-issues-via-commit-messages
4b076bahttps://github.com/hardikkaurani/durabletask-python/commit/4b076bacca87e7daf30d7dd7164afe2c7c7cdc31
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/durabletask-python/issues/299
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/durabletask-python/issues/299
bugSomething isn't workinghttps://github.com/microsoft/durabletask-python/issues?q=state%3Aopen%20label%3A%22bug%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.