Title: Cancelling a subscription consumer leaves its source running with an AbortSignal · Issue #322 · graphql-python/graphql-core · GitHub
Open Graph Title: Cancelling a subscription consumer leaves its source running with an AbortSignal · Issue #322 · graphql-python/graphql-core
X Title: Cancelling a subscription consumer leaves its source running with an AbortSignal · Issue #322 · graphql-python/graphql-core
Description: Cancelling a task awaiting the next subscription event leaves its source running when an idle AbortSignal is supplied. Without the signal, the same cancellation closes the source immediately. This can leave a subscription’s pending I/O a...
Open Graph Description: Cancelling a task awaiting the next subscription event leaves its source running when an idle AbortSignal is supplied. Without the signal, the same cancellation closes the source immediately. This ...
X Description: Cancelling a task awaiting the next subscription event leaves its source running when an idle AbortSignal is supplied. Without the signal, the same cancellation closes the source immediately. This ...
Opengraph URL: https://github.com/graphql-python/graphql-core/issues/322
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cancelling a subscription consumer leaves its source running with an AbortSignal","articleBody":"Cancelling a task awaiting the next subscription event leaves its source running when an idle `AbortSignal` is supplied. Without the signal, the same cancellation closes the source immediately. This can leave a subscription’s pending I/O alive after a client disconnect or request timeout.\n\nReproduced on main `2bd255772890e0b32241d793b3ee10a067c20cfd` (GraphQL-core 3.3.2), Python 3.14.4.\n\n```python\n\"\"\"Public subscription cancellation with an idle AbortSignal, compared to no signal.\"\"\"\nimport asyncio\nimport contextlib\nimport json\nfrom graphql import build_schema, parse, subscribe\nfrom graphql.pyutils import AbortController\n\nasync def probe(with_signal):\n started = asyncio.Event()\n release = asyncio.Event()\n closed = asyncio.Event()\n delivered = []\n\n async def events():\n try:\n started.set()\n await release.wait()\n delivered.append('event after request cancellation')\n yield {'event': 'value'}\n finally:\n closed.set()\n\n source = events()\n controller = AbortController()\n schema = build_schema('type Query { unused: String } type Subscription { event: String }')\n kwargs = {'abort_signal': controller.signal} if with_signal else {}\n stream = subscribe(schema, parse('subscription { event }'), root_value={'event': source}, **kwargs)\n consumer = asyncio.create_task(anext(stream))\n await asyncio.wait_for(started.wait(), 1)\n consumer.cancel()\n with contextlib.suppress(asyncio.CancelledError):\n await consumer\n snapshot = {'with_signal': with_signal, 'consumer_cancelled': consumer.cancelled(),\n 'source_closed_after_cancel': closed.is_set(), 'signal_aborted': controller.signal.aborted,\n 'pending_source_tasks': [t.get_coro().__class__.__name__ for t in asyncio.all_tasks()\n if t is not asyncio.current_task() and not t.done()]}\n release.set()\n for _ in range(10):\n await asyncio.sleep(0)\n snapshot['events_after_cancel'] = delivered.copy()\n # Explicitly close the retained source so this reproduction leaves no work behind.\n await source.aclose()\n await stream.aclose()\n print(json.dumps(snapshot), flush=True)\n return snapshot\n\nasync def main():\n control = await probe(False)\n affected = await probe(True)\n assert control['source_closed_after_cancel']\n assert control['events_after_cancel'] == []\n assert affected['source_closed_after_cancel'], 'AbortSignal causes cancelled subscription source to remain active'\n\nasyncio.run(main())\n```\n\nThe no-signal case reports `source_closed_after_cancel=true` and no delivered events. With the idle signal, it reports `false`, retains an `async_generator_asend` task, and produces an event when released after cancellation. The reproduction closes the remaining source before its final assertion fails.\n\n`Executor.with_abort_signal` creates the source task and waits with `asyncio.wait`. Caller cancellation cleans up the abort-wait task, while the source task continues. I’d like to fix this by cancelling and settling the owned source task on `CancelledError`, with a focused regression. Does that fit the intended behavior?\n","author":{"url":"https://github.com/AryanRG","@type":"Person","name":"AryanRG"},"datePublished":"2026-11-17T15:34:13Z","url":"https://github.com/graphql-python/graphql-core/issues/322"}
| 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:1eaa54ca-be6c-24ed-ea61-db7a7353419e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0B8:2148FB:1905CE0:21AF44C:6AFFF4CF |
| html-safe-nonce | 08005d01de3eb2dd00adf6d083bbb86621359f244a39b8cff715ce3c3a5094b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEI4OjIxNDhGQjoxOTA1Q0UwOjIxQUY0NEM6NkFGRkY0Q0YiLCJ2aXNpdG9yX2lkIjoiMzg4NzE4OTMwMjk4Mjk5NzE5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d33e14f354a4c79c1d5fae1ffb416d7eaec09eb127d50c495e74cb62e015594e |
| hovercard-subject-tag | issue:6448107665 |
| 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/322/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fa7c12327511a8bd1a0e5831d2e957833f99ef5f07e8dd35daf2c1d895863739/graphql-python/graphql-core/issues/322 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fa7c12327511a8bd1a0e5831d2e957833f99ef5f07e8dd35daf2c1d895863739/graphql-python/graphql-core/issues/322 |
| og:image:alt | Cancelling a task awaiting the next subscription event leaves its source running when an idle AbortSignal is supplied. Without the signal, the same cancellation closes the source immediately. This ... |
| 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 | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width