python-trio / python-trio/trio

"Cancel scope stack corrupted" is thrown when recursion depth exceeded

Open
#1,817 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

The following code:

import trio

def f():
    with trio.move_on_after(1):
        f()

trio.run(f)

Fails with:

RuntimeError: Cancel scope stack corrupted: attempted to exit <trio.CancelScope at 0x7f451b880130, active, deadline is 1.00 seconds from now> in <Task '<init>' at 0x7f451ba35ed0> that's still within its child <trio.CancelScope at 0x7f451b880210, active, deadline is 1.00 seconds from now>

Way up the stack trace, there's also a RecursionError: maximum recursion depth exceeded in comparison. Neither of those are the errors I'd expect; I'd expect a simple RecursionError: maximum recursion depth exceeded.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the recursive f(), trio.move_on_after(), and trio.run() entry points shown in the issue, then trace how recursion exhaustion is handled while nested cancel scopes exit. Done means the example raises the expected plain RecursionError instead of the cancel-scope corruption RuntimeError.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.