Skip to content

get_all_awaited_by() shows incorrect call stacks in awaited_by relationships #135371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pablogsal opened this issue Jun 11, 2025 · 0 comments
Open
Labels
type-bug An unexpected behavior, bug, or error

Comments

@pablogsal
Copy link
Member

pablogsal commented Jun 11, 2025

Bug report

Bug description:

The get_all_awaited_by() function in the remote debugging module was returning incorrect call stack information in the awaited_by relationships. Instead of showing each task's own call stack, it was showing the awaiter's call stack, making the output confusing and misleading.

Expected Behavior

Each task should show:

  • Its own call stack (where the task is currently executing)
  • The task ID of who is awaiting it

Actual Behavior

Each task was showing:

  • The awaiter's call stack (where the awaiter is executing)
  • The task's own ID (instead of the awaiter's ID)

Example

For this code:

async def foo1():
    await foo11()
async def foo11():
    await foo12()  
async def foo12():
    await asyncio.sleep(1000)  # foo1.0 task is here

async def runner():
    async with TaskGroup() as g:
        g.create_task(foo1(), name="foo1.0")
        await asyncio.sleep(1000)  # runner/Task-1 is here

Wrong output:

foo1.0: call_stack=[sleep -> runner], awaiter_id=foo1.0  # Shows runner's stack!

Correct output:

foo1.0: call_stack=[sleep -> foo12 -> foo11 -> foo1], awaiter_id=Task-1  # Shows foo1.0's own stack!

In process_single_task_node(), the code is calling parse_task_awaited_by() which traverses to the awaiter and gets the awaiter's call stack instead of the current task's call stack.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@pablogsal pablogsal added the type-bug An unexpected behavior, bug, or error label Jun 11, 2025
pablogsal added a commit to pablogsal/cpython that referenced this issue Jun 11, 2025
…gging

The awaited_by list in get_all_awaited_by() was incorrectly showing the
awaiter's call stack instead of the current task's call stack. This made
the output confusing and incorrect.

This change adds a new parse_current_task_with_awaiter() function that
correctly extracts the current task's own call stack (where it's
executing) and the awaiter's task ID (who is waiting for this task).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant