Title: Closing a subscription leaves a distinct source iterator open · Issue #283 · graphql-python/graphql-core · GitHub
Open Graph Title: Closing a subscription leaves a distinct source iterator open · Issue #283 · graphql-python/graphql-core
X Title: Closing a subscription leaves a distinct source iterator open · Issue #283 · graphql-python/graphql-core
Description: On current main (d913a61), map_async_iterable registers cleanup on the async iterable object, while async iteration consumes the object returned by its aiter method. A valid wrapper can return a separate async generator. Closing the mapp...
Open Graph Description: On current main (d913a61), map_async_iterable registers cleanup on the async iterable object, while async iteration consumes the object returned by its aiter method. A valid wrapper can return a se...
X Description: On current main (d913a61), map_async_iterable registers cleanup on the async iterable object, while async iteration consumes the object returned by its aiter method. A valid wrapper can return a se...
Opengraph URL: https://github.com/graphql-python/graphql-core/issues/283
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Closing a subscription leaves a distinct source iterator open","articleBody":"On current main (d913a6106ffe2e459b91dce97f225d15723aa81d), map_async_iterable registers cleanup on the async iterable object, while async iteration consumes the object returned by its __aiter__ method. A valid wrapper can return a separate async generator. Closing the mapped stream then leaves that generator open, so its finally block does not run. The same behavior is reachable through subscribe().\n\nMinimal reproducer:\n\n```python\nimport asyncio\nfrom graphql.execution.async_iterables import map_async_iterable\n\nasync def main():\n closed = False\n\n async def events():\n nonlocal closed\n try:\n yield 1\n yield 2\n finally:\n closed = True\n\n iterator = events()\n\n class Events:\n def __aiter__(self):\n return iterator\n\n async def identity(value):\n return value\n\n mapped = map_async_iterable(Events(), identity)\n try:\n assert await anext(mapped) == 1\n await mapped.aclose()\n assert closed # Fails: the source iterator is still open.\n finally:\n await iterator.aclose()\n\nasyncio.run(main())\n```\n\nExpected: closing the mapped stream awaits cleanup of the iterator actually supplying events. Actual: cleanup is attempted on the wrapper; the generator remains open and can yield the second event.\n\nA narrow local fix acquires the iterator before registering cleanup (aclosing(aiter(iterable))). Four new regressions fail on the base and pass with that change, including one through the public subscription API. The full local suites pass on Python 3.10 and 3.14. This differs from the broader AnyIO/cancellation work in #165 and #166; it does not change pending-next cancellation behavior.\n\nDoes closing the consumed iterator match the intended port contract? I can link the focused patch after discussion, following the PR template. AI assistance was used to investigate and validate this report.","author":{"url":"https://github.com/AryanRG","@type":"Person","name":"AryanRG"},"datePublished":"2026-10-17T04:08:35Z","url":"https://github.com/graphql-python/graphql-core/issues/283"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c31fdaee-6fee-fe02-3c23-887324c034d7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF68:2EBAD:826B1:ADED4:6B001908 |
| html-safe-nonce | 6d6e9fb47f5d9461ca6485c847a2239c1f8146ba3d42b64b62a8360e2fdbd511 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjY4OjJFQkFEOjgyNkIxOkFERUQ0OjZCMDAxOTA4IiwidmlzaXRvcl9pZCI6Ijg1MTU2OTYxMDAyNDAzMjUyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ae41894ce1eb547f87b157065adf0f139eb8413705fabf957fd30cb0e1050bf4 |
| hovercard-subject-tag | issue:5894694626 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/graphql-python/graphql-core/283/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f40e512d7d7afe02c8bfaae3521dc26c666c195ebe62de36cec8c9582014462c/graphql-python/graphql-core/issues/283 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f40e512d7d7afe02c8bfaae3521dc26c666c195ebe62de36cec8c9582014462c/graphql-python/graphql-core/issues/283 |
| og:image:alt | On current main (d913a61), map_async_iterable registers cleanup on the async iterable object, while async iteration consumes the object returned by its aiter method. A valid wrapper can return a se... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AryanRG |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-python/graphql-core git https://github.com/graphql-python/graphql-core.git |
| octolytics-dimension-user_id | 15002022 |
| octolytics-dimension-user_login | graphql-python |
| octolytics-dimension-repository_id | 143207933 |
| octolytics-dimension-repository_nwo | graphql-python/graphql-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143207933 |
| octolytics-dimension-repository_network_root_nwo | graphql-python/graphql-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width