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

stack overflow after hitting recursion limit twice #49642

Closed
ggenellina mannequin opened this issue Feb 28, 2009 · 8 comments
Closed

stack overflow after hitting recursion limit twice #49642

ggenellina mannequin opened this issue Feb 28, 2009 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@ggenellina
Copy link
Mannequin

ggenellina mannequin commented Feb 28, 2009

BPO 5392
Nosy @loewis, @birkenfeld, @pitrou
Files
  • issue5392.patch
  • 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 = 'https://github.com/pitrou'
    closed_at = <Date 2009-03-13.21:00:44.410>
    created_at = <Date 2009-02-28.11:26:43.669>
    labels = ['interpreter-core', 'type-crash']
    title = 'stack overflow after hitting recursion limit twice'
    updated_at = <Date 2009-03-13.21:00:44.409>
    user = 'https://bugs.python.org/ggenellina'

    bugs.python.org fields:

    activity = <Date 2009-03-13.21:00:44.409>
    actor = 'pitrou'
    assignee = 'pitrou'
    closed = True
    closed_date = <Date 2009-03-13.21:00:44.410>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2009-02-28.11:26:43.669>
    creator = 'ggenellina'
    dependencies = []
    files = ['13218']
    hgrepos = []
    issue_num = 5392
    keywords = ['patch']
    message_count = 8.0
    messages = ['82906', '82909', '82916', '82967', '82968', '82969', '82979', '83533']
    nosy_count = 4.0
    nosy_names = ['loewis', 'georg.brandl', 'ggenellina', 'pitrou']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue5392'
    versions = ['Python 3.0', 'Python 3.1']

    @ggenellina
    Copy link
    Mannequin Author

    ggenellina mannequin commented Feb 28, 2009

    Set sys.setrecursionlimit to 50 or lower. Then, the second time the
    recursion limit is reached, the interpreter crashes with a stack
    overflow.
    This happens both with released 3.0.1 and the py3k branch, on Windows.
    At least on my PC, 51 appears to be the minimum acceptable value for
    sys.setrecursionlimit.

    Python 3.1a0 (py3k, Feb 28 2009, 04:16:04) [MSC v.1500 32 bit (Intel)] 
    on win32
    Type "help", "copyright", "credits" or "license" for more information.
    p3> import sys
    p3> sys.setrecursionlimit(20)
    p3> def g(): g()
    ...
    p3> g()
    Traceback (most recent call last):
    ...
    RuntimeError: maximum recursion depth exceeded
    p3> g()
    Fatal Python error: Cannot recover from stack overflow.

    This application has requested the Runtime to terminate it in an
    unusual way.
    Please contact the application's support team for more information.

    C:\APPS\python\py3k\PCbuild>

    @ggenellina ggenellina mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Feb 28, 2009
    @birkenfeld
    Copy link
    Member

    I can reproduce that (with the same limits) on Linux here.
    It doesn't happen with 2.6.

    (Although it is technically not a crash but a controlled abort().)

    @pitrou
    Copy link
    Member

    pitrou commented Feb 28, 2009

    This is probably due to the recursion overflow recovery code in py3k,
    which has a hard-wired constant of 50 somewhere :-)

    (is setting the recursion limit so low a requirement for your
    application? or were you just experimenting with it? as Georg said, it's
    not a crash but a deliberate fatal error... although we can probably
    change the behaviour when the recursion limit is set to 50 or lower)

    @ggenellina
    Copy link
    Mannequin Author

    ggenellina mannequin commented Mar 1, 2009

    It is an artificial value, I don't require a recursion
    limit so low in any application. I found it when
    looking into bpo-5370.
    If there is a lower limit to sys.setrecursionlimit,
    maybe it should be enforced. But since it fails only
    the second time, it looks like a bug somewhere.

    @pitrou
    Copy link
    Member

    pitrou commented Mar 1, 2009

    The fact it fails only the second time is by design, although I'm not
    sure the design is useful, and it's probably not documented anywhere.
    The error message says it : "Cannot *recover* from stack overflow",
    which means there was a first stack overflow, and Python thinks it has
    failed recovering from it since a second stack overflow occurred
    afterwards.

    We could probably make the recovery detection smarter.

    @pitrou pitrou self-assigned this Mar 1, 2009
    @pitrou
    Copy link
    Member

    pitrou commented Mar 1, 2009

    Here is a patch. I've put the tests in test_sys.py, I haven't found a
    better place for them.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Mar 1, 2009

    The fact it fails only the second time is by design, although I'm not
    sure the design is useful, and it's probably not documented anywhere.

    It helped me debug a number of interpreter crashes in 3.0. When a stack
    overflow occurred, in certain cases, the interpreter would catch the
    exception, and consider it as failure in the callback it tried to invoke
    (e.g. when invoking __eq__ during dictionary lookups). Rather than
    letting the stack unwind, it would continue to let the stack overflow,
    and eventually managed to crash the entire process. The recovery check
    is there to detect that, after a stack overflow, it really unwound a
    sufficient number of stack frames, rather than overflowing again and
    again.

    @pitrou
    Copy link
    Member

    pitrou commented Mar 13, 2009

    Committed in r70344.

    @pitrou pitrou closed this as completed Mar 13, 2009
    @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
    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

    2 participants