Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tests that exhaust the C stack fail, hang, or consume all memory when the stack limit is huge #154211

Description

@serhiy-storchaka

Bug report

Many tests that expect RecursionError from C stack exhaustion misbehave when the stack limit is very large (DragonFly BSD's default is 512 MiB; ulimit -s can be raised up to unlimited). Tests with a fixed recursion depth fail:

$ ulimit -s 524288
$ ./python -m test test_dict -m test_repr_deep
AssertionError: RecursionError not raised by repr

or run for minutes (deep repr() is quadratic). Tests with unbounded recursion take time proportional to the stack limit (test_ast.test_recursion_direct: 66 ms with 8 MiB, 43 s with 16 GiB), crash with a segmentation fault, or consume all memory. This breaks the default test suite run on DragonFly BSD and on Linux with a raised stack limit.

@support.skip_if_unlimited_stack_size (gh-143460) only covers a truly unlimited stack, and some of its client tests also break or slow down with a large finite limit.

Add a @support.skip_if_huge_c_stack(depth) decorator which skips a test if _testinternalcapi.get_c_recursion_remaining() reports that recursion to the given depth cannot trigger the protection (including a negative result from integer overflow with an unlimited stack), falling back to the unlimited-stack check if _testinternalcapi is not available. Use it in the affected tests, and remove @skip_if_unlimited_stack_size where it becomes redundant.

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

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions