Skip to content
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

Recursion causes Crash #88953

Closed
michaeljwang10 mannequin opened this issue Jul 31, 2021 · 4 comments
Closed

Recursion causes Crash #88953

michaeljwang10 mannequin opened this issue Jul 31, 2021 · 4 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@michaeljwang10
Copy link
Mannequin

michaeljwang10 mannequin commented Jul 31, 2021

BPO 44790
Nosy @sweeneyde, @jdevries3133
Files
  • bug.py: Use the following code to replicate the bug
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-07-31.03:45:52.992>
    created_at = <Date 2021-07-31.02:20:58.105>
    labels = ['interpreter-core', '3.7', 'invalid', 'type-crash']
    title = 'Recursion causes Crash'
    updated_at = <Date 2021-07-31.03:45:52.991>
    user = 'https://bugs.python.org/michaeljwang10'

    bugs.python.org fields:

    activity = <Date 2021-07-31.03:45:52.991>
    actor = 'Dennis Sweeney'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-31.03:45:52.992>
    closer = 'Dennis Sweeney'
    components = ['Interpreter Core']
    creation = <Date 2021-07-31.02:20:58.105>
    creator = 'michaeljwang10'
    dependencies = []
    files = ['50193']
    hgrepos = []
    issue_num = 44790
    keywords = []
    message_count = 4.0
    messages = ['398619', '398622', '398623', '398627']
    nosy_count = 3.0
    nosy_names = ['Dennis Sweeney', 'jack__d', 'michaeljwang10']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue44790'
    versions = ['Python 3.7']

    @michaeljwang10
    Copy link
    Mannequin Author

    michaeljwang10 mannequin commented Jul 31, 2021

    Ultimately it seems that deep recursion after setting the recursion limit actually crashes python

    @michaeljwang10 michaeljwang10 mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 31, 2021
    @jdevries3133
    Copy link
    Mannequin

    jdevries3133 mannequin commented Jul 31, 2021

    The default recursion limit is 1,000; you're increasing it by a factor of 10. It is documented that raising the recursion limit can cause crashes. What kind of crash are you seeing? Segmentation fault or stack overflow? Also, provide more details about your system: what OS and more importantly in this case, how much RAM?

    It's possible that this is not a bug.

    @jdevries3133
    Copy link
    Mannequin

    jdevries3133 mannequin commented Jul 31, 2021

    Also, see related: bpo-44393

    @sweeneyde
    Copy link
    Member

    Indeed, this behavior is documented at https://docs.python.org/3/library/sys.html?highlight=setrecursionlimit#sys.setrecursionlimit : "a too-high limit can lead to a crash".

    I'd recommend refactoring to use iteration rather than recursion:

        def fact(n):
            product = 1
            for i in range(1, n+1):
                product *= i
            return product

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant