René's URL Explorer Experiment


Title: test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CI · Issue #157157 · python/cpython · GitHub

Open Graph Title: test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CI · Issue #157157 · python/cpython

X Title: test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CI · Issue #157157 · python/cpython

Description: Bug report Bug description: test_taskgroup_cancel_keeps_outer_cancellation (added by gh-155433 in ee23046) failed on the "Sanitizers / TSan (free-threading)" CI job of an unrelated PR: https://github.com/python/cpython/actions/runs/34184...

Open Graph Description: Bug report Bug description: test_taskgroup_cancel_keeps_outer_cancellation (added by gh-155433 in ee23046) failed on the "Sanitizers / TSan (free-threading)" CI job of an unrelated PR: https://gith...

X Description: Bug report Bug description: test_taskgroup_cancel_keeps_outer_cancellation (added by gh-155433 in ee23046) failed on the "Sanitizers / TSan (free-threading)" CI job of an unrelated PR: ht...

Opengraph URL: https://github.com/python/cpython/issues/157157

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CI","articleBody":"# Bug report\n\n### Bug description:\n\n`test_taskgroup_cancel_keeps_outer_cancellation` (added by gh-155433 in ee23046d64) failed on the \"Sanitizers / TSan (free-threading)\" CI job of an unrelated PR: https://github.com/python/cpython/actions/runs/34184752621/job/101930777575\n\n```\nERROR: test_taskgroup_cancel_keeps_outer_cancellation (test.test_asyncio.test_taskgroups.TestTaskGroup.test_taskgroup_cancel_keeps_outer_cancellation)\nTraceback (most recent call last):\n  File \".../Lib/test/test_asyncio/test_taskgroups.py\", line 1220, in test_taskgroup_cancel_keeps_outer_cancellation\n    self.assertEqual('message', cm.exception.args[0])\nIndexError: tuple index out of range\n```\n\nThe test relies on timing. It starts the body task, does `await asyncio.sleep(0.01)`, then calls `task.cancel('message')`, expecting the outer cancellation to arrive while the group is still waiting for its child (whose `finally` sleeps for 0.1 s). The `CancelledError` that comes out carries no message when the loop stalls for more than 10 ms between arming that timer and running the body's first step (for example a GC pause, or the general slowness of a sanitizer build: the same job log reports single callbacks taking more than 0.1 s).\n\nWhat happens in that ordering:\n\n1. The timer expires before the iteration that runs the body's first step, so the timer callback is queued right behind it and the outer coroutine resumes in the next iteration, ahead of the group's own wakeup.\n2. Meanwhile the body has called `tg.cancel()`, which cancels the parent task; when `TaskGroup._aexit()` awaits `_on_completed_fut`, `Task.__step()` cancels that future immediately (no message) and schedules the wakeup.\n3. The outer `task.cancel('message')` now runs while `_fut_waiter` is that already-cancelled future, so `Task.cancel()` cannot cancel it and falls back to `_must_cancel = True` with the message.\n4. The wakeup then calls `__step(exc)` with the message-less `CancelledError` from the future, and since `exc` is already a `CancelledError`, `_must_cancel` is cleared without using `_cancel_message`. The group re-raises that message-less error at the end of `_aexit()`.\n\nReproducer, simulating the stall with `time.sleep()` after the timer is armed (the eager-task variant is not affected, because there the body's first step has already run when the timer is armed):\n\n```python\nimport asyncio, time\n\nasync def main():\n    loop = asyncio.get_running_loop()\n\n    async def child():\n        try:\n            await asyncio.sleep(10)\n        finally:\n            await asyncio.sleep(0.1)\n\n    async def body():\n        async with asyncio.TaskGroup() as tg:\n            tg.create_task(child())\n            await asyncio.sleep(0)\n            tg.cancel()\n\n    task = asyncio.create_task(body())\n    fut = loop.create_future()\n    loop.call_later(0.01, fut.set_result, None)  # what asyncio.sleep(0.01) does\n    time.sleep(0.02)                              # the loop stalls\n    await fut\n    task.cancel('message')\n    try:\n        await task\n    except asyncio.CancelledError as exc:\n        print(exc.args)   # () instead of ('message',)\n\nasyncio.run(main())\n```\n\nThe test can be made deterministic by synchronizing on events instead of sleeping: have the child signal from its `finally` block that the group is cancelling and wait there for the test to release it, and only then cancel the parent task from outside. I have a PR for that.\n\nWhether `Task.cancel(msg)` should keep the message when it is called between the cancellation of the awaited future and the task's next step (step 3 and 4 above) is a separate question; I have not changed that.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux (CI), macOS (reproducer)\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157158\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/iamsharduld","@type":"Person","name":"iamsharduld"},"datePublished":"2026-09-08T04:16:33Z","url":"https://github.com/python/cpython/issues/157157"}

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:ebe2a1a9-8120-c9f7-4e73-28de3dc823b0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAEC0:842EC:32F45B4:43EF18D:6B01F9F1
html-safe-nonce0f646c34111f27870b0083bea2219e935b6932ca70d562c4fd9cc70b810fcb9d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUMwOjg0MkVDOjMyRjQ1QjQ6NDNFRjE4RDo2QjAxRjlGMSIsInZpc2l0b3JfaWQiOiI0ODI1NjYxNjEzMDMxOTQ2NzM3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacfaf9a1f186910bb1ae77c16502c52ae2098dad0018a3801cde5b93ec859d7ee2
hovercard-subject-tagissue:5381954627
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/python/cpython/157157/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fa257bb4ed090f00c91bf36d057d6c1bc53581d3bfff88fd871ffdc9d7eaa186/python/cpython/issues/157157
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fa257bb4ed090f00c91bf36d057d6c1bc53581d3bfff88fd871ffdc9d7eaa186/python/cpython/issues/157157
og:image:altBug report Bug description: test_taskgroup_cancel_keeps_outer_cancellation (added by gh-155433 in ee23046) failed on the "Sanitizers / TSan (free-threading)" CI job of an unrelated PR: https://gith...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameiamsharduld
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/157157#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F157157
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%2Fpython%2Fcpython%2Fissues%2F157157
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=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/157157
Reloadhttps://github.com/python/cpython/issues/157157
Reloadhttps://github.com/python/cpython/issues/157157
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/157157
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/157157
test_taskgroup_cancel_keeps_outer_cancellation is timing-dependent and fails on slow (TSan) CIhttps://github.com/python/cpython/issues/157157#top
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
https://github.com/iamsharduld
iamsharduldhttps://github.com/iamsharduld
on Sep 8, 2026https://github.com/python/cpython/issues/157157#issue-5381954627
gh-155433https://github.com/python/cpython/issues/155433
ee23046https://github.com/python/cpython/commit/ee23046d64a4bd78a5a02a4a1b3afa80b60a64fa
https://github.com/python/cpython/actions/runs/34184752621/job/101930777575https://github.com/python/cpython/actions/runs/34184752621/job/101930777575
gh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation deterministic #157158https://github.com/python/cpython/pull/157158
https://github.com/iamsharduld
iamsharduldhttps://github.com/iamsharduld
on Sep 8, 2026https://github.com/python/cpython/issues/157157#issuecomment-5579342999
https://github.com/python/cpython/actions/runs/34144006578/job/101812010057https://github.com/python/cpython/actions/runs/34144006578/job/101812010057
aiskhttps://github.com/aisk
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
on Sep 8, 2026https://github.com/python/cpython/issues/157157#event-30733457852
kumaraditya303https://github.com/kumaraditya303
on Sep 11, 2026https://github.com/python/cpython/issues/157157#event-30972110323
gh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation determ…https://github.com/python/cpython/commit/1c641ff2c3e57acaae27d36b6b30839e585ac090
gh-157157https://github.com/python/cpython/issues/157157
1c641ffhttps://github.com/python/cpython/commit/1c641ff2c3e57acaae27d36b6b30839e585ac090
kumaraditya303https://github.com/kumaraditya303
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 11, 2026https://github.com/python/cpython/issues/157157#event-30972187683
clin1234https://github.com/clin1234
on Sep 12, 2026https://github.com/python/cpython/issues/157157#event-31023922975
pythongh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation …https://github.com/clin1234/cpython/commit/e8cdbd2bc24aad31e931543b44724b082f56fcc7
pythongh-157157https://github.com/python/cpython/issues/157157
e8cdbd2https://github.com/clin1234/cpython/commit/e8cdbd2bc24aad31e931543b44724b082f56fcc7
johnslavikhttps://github.com/johnslavik
on Sep 14, 2026https://github.com/python/cpython/issues/157157#event-31099057981
pythongh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation …https://github.com/johnslavik/cpython/commit/079e137e8f387f3b901a6295572fbe6f3e9b8d13
pythongh-157157https://github.com/python/cpython/issues/157157
079e137https://github.com/johnslavik/cpython/commit/079e137e8f387f3b901a6295572fbe6f3e9b8d13
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/157157
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/157157
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%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.