python-trio / python-trio/trio
Internal error with recursive tasks and cancellation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
I'm not really sure the cause of this nor whether we can fix this... Related to https://github.com/python-trio/trio/issues/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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the recursive cancellation reproducer and trace the reported path through src/trio/_core/_run.py, especially unrolled_run, task_exited, and _child_finished. Investigate why repeated Ctrl+C and nested nurseries produce a RecursionError while handling the child outcome; done means the reproducer no longer raises TrioInternalError or exceeds recursion depth.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100