GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cancellation leaks out of asyncio.TaskGroup on 3.12 when using eager tasks · Issue #128588 · python/cpython

Cancellation leaks out of asyncio.TaskGroup on 3.12 when using eager tasks #128588

New issue
Copy link
New issue
Copy link
Closed
Closed
Cancellation leaks out of asyncio.TaskGroup on 3.12 when using eager tasks#128588
Copy link
Labels
3.12only security fixesonly security fixestopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@graingert
graingert
opened on Jan 7, 2025
Issue body actions

Bug report

Bug description:

import sys
import asyncio

if sys.platform == "win32":
    EventLoop = asyncio.ProactorEventLoop
else:
    EventLoop = asyncio.SelectorEventLoop


async def demo():
    class MyError(Exception):
        pass

    async def throw_error():
        raise MyError

    try:
        async with asyncio.TaskGroup() as tg:
            tg.create_task(throw_error())
    except* MyError:
        pass


def loop_factory():
    loop = EventLoop()
    loop.set_task_factory(asyncio.eager_task_factory)
    return loop

asyncio.run(demo(), loop_factory=loop_factory)

results in:

Traceback (most recent call last):
  File "/home/graingert/projects/anyio/demo.py", line 29, in <module>
    asyncio.run(demo(), loop_factory=loop_factory)
  File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

  • gh-128588: gh-128550: remove eager tasks optimization that missed and introduced incorrect cancellations #129063
  • [3.13] gh-128588: gh-128550: remove eager tasks optimization that missed and introduced incorrect cancellations (GH-129063) #129089
  • [3.12] gh-128588: gh-128550: gh-128552: fix refcycles in eager task creation (#128553) and remove eager tasks optimization that missed and introduced incorrect cancellations (python#129063) #128586

Activity

  1. graingert
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.12only security fixesonly security fixes
    on Jan 7, 2025
  2. graingert commented on Jan 7, 2025

    @graingert
    graingert
    on Jan 7, 2025
    ContributorAuthor
    More actions

    I think related to #116720 but a lot easier to trigger by accident.

  3. graingert
    added
    topic-asyncio
    on Jan 7, 2025
  4. kumaraditya303 commented on Jan 8, 2025

    @kumaraditya303
    kumaraditya303
    on Jan 8, 2025
    Contributor
    More actions

    This seems fixed on main. Perhaps we missed backporting a fix for it?

  5. graingert commented on Jan 8, 2025

    @graingert
    graingert
    on Jan 8, 2025
    ContributorAuthor
    More actions

    I believe it was intentionally not backported because the conditions to trigger it were thought to be a bit complex and it needed a change to how Task.cancel worked (re unsetting must_cancel)

  6. kumaraditya303 commented on Jan 8, 2025

    @kumaraditya303
    kumaraditya303
    on Jan 8, 2025
    Contributor
    More actions

    cc @gvanrossum

  7. graingert
    added 2 commits that reference this issue on Jan 20, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    0fe00b5

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    9fce599
  8. kumaraditya303
    added a commit that references this issue on Jan 20, 2025

    gh-128588: gh-128550: remove eager tasks optimization that missed and…

    ed6934e
  9. miss-islington
    added a commit that references this issue on Jan 20, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    70fb2d0
  10. kumaraditya303
    added a commit that references this issue on Jan 20, 2025

    [3.13] gh-128588: gh-128550: remove eager tasks optimization that mis…

    a1c48a7
  11. graingert
    added a commit that references this issue on Jan 20, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    59aff22
  12. kumaraditya303
    added a commit that references this issue on Jan 21, 2025

    [3.12] gh-128588: fix refcycles in eager task creation and remove eag…

    bc21454
  13. srinivasreddy
    added a commit that references this issue on Jan 21, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    c765847
  14. kumaraditya303
    closed this as completedon Jan 21, 2025
  15. github-project-automation
    moved this to Done in asyncioon Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixestopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • asyncio
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.