Skip to content

asyncio.gather() doesn't clear await edge in graph #157213

Description

@deadlovelll

Bug report

Bug description:

asyncio.gather() leaves a task as awaited by caller in the graph, but it actually not

import asyncio

async def survivor():
    await asyncio.Future()

async def boom():
    raise ValueError

async def main():
    s = asyncio.ensure_future(survivor())
    try:
        await asyncio.gather(s, boom())
    except ValueError:
        print("valueerror")
    asyncio.print_call_graph(s)
    s.cancel()

asyncio.run(main())

Expected:

❯ ./python repro.py
valueerror
* Task(name='Task-2', id=0x719b21d58b90)
  + Call stack:
  |   File '/home/timofei/Desktop/cpython/repro.py', line 4, in async survivor()

Actual:

❯ ./python repro.py
valueerror
* Task(name='Task-2', id=0x7fe4a47e0b90)
  + Call stack:
  |   File '/home/timofei/Desktop/cpython/repro.py', line 4, in async survivor()
  + Awaited by:
    * Task(name='Task-1', id=0x7fe4a47e0d70)
      + Call stack:
      |   File '/home/timofei/Desktop/cpython/repro.py', line 15, in async main()

Proposed fix: discard edges on the gather future

I have a fix ready for that

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

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

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions