Skip to content

Internal error with recursive tasks and cancellation #3290

@A5rocks

Description

@A5rocks

I'm not really sure the cause of this nor whether we can fix this... Related to #3289

Reproducing program:

import trio

async def sub_tn():
    async with trio.open_nursery() as tn:
        tn.start_soon(trio.sleep_forever)
        tn.start_soon(sub_tn)
        try:
            await trio.sleep_forever()
        finally:
            await trio.lowlevel.checkpoint()
    

async def main():
    async with trio.open_nursery() as tn:
        tn.start_soon(trio.sleep_forever)
        tn.start_soon(sub_tn)
        await trio.sleep(2)
        tn.cancel_scope.cancel()

trio.run(main)

When I hit Ctrl+C a bunch while it runs, I get this error:

Traceback (most recent call last):
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_run.py", line 2875, in unrolled_run
    runner.task_exited(task, final_outcome)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_run.py", line 2053, in task_exited
    task._parent_nursery._child_finished(task, outcome)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_run.py", line 1270, in _child_finished
    reason=f"child task raised exception {outcome.error!r}",
                                         ^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\A5rocks\Documents\trio\repro.py", line 23, in <module>
    trio.run(main)
    ~~~~~~~~^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_run.py", line 2518, in run
    timeout = gen.send(next_send)
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_run.py", line 2931, in unrolled_run
    raise TrioInternalError("internal error in Trio - please file a bug!") from exc
trio.TrioInternalError: internal error in Trio - please file a bug!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions