Skip to content

Recursive traceback crashes Python Interpreter #86817

Closed

Description

@xxm
mannequin
BPO 42651
Nosy @ronaldoussoren, @stestagg
Superseder
  • bpo-42500: crash with unbounded recursion in except statement
  • 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 2020-12-22.08:32:24.480>
    created_at = <Date 2020-12-16.08:02:14.969>
    labels = ['interpreter-core', '3.8', '3.9', '3.10', '3.7', 'type-crash']
    title = 'Recursive traceback crashes  Python Interpreter'
    updated_at = <Date 2020-12-22.08:32:24.480>
    user = 'https://bugs.python.org/xxm'

    bugs.python.org fields:

    activity = <Date 2020-12-22.08:32:24.480>
    actor = 'ronaldoussoren'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-12-22.08:32:24.480>
    closer = 'ronaldoussoren'
    components = ['Interpreter Core']
    creation = <Date 2020-12-16.08:02:14.969>
    creator = 'xxm'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42651
    keywords = []
    message_count = 6.0
    messages = ['383118', '383249', '383253', '383267', '383268', '383575']
    nosy_count = 3.0
    nosy_names = ['ronaldoussoren', 'xxm', 'stestagg']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = '42500'
    type = 'crash'
    url = 'https://bugs.python.org/issue42651'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    Activity

    1. xxm commented on Dec 16, 2020

      xxmmannequin
      MannequinAuthor

      =================

      import traceback
      
      def foo():
        traceback.print_exc()
        foo() 
          
      foo()

      ================

      Try running the above program, the interpreter is crashed with the error message like the following:

      Fatal Python error: Cannot recover from stack overflow.
      NoneType: None
      NoneType: None
      NoneType: None
      NoneType: None

      ...
      NoneType: None

      NoneType: None
      NoneType: <unprintable NoneType object>
      NoneType: None
      NoneType: None
      ...
      NoneType: None
      NoneType: None
      NoneType: None
      Fatal Python error: _Py_CheckRecursiveCall: Cannot recover from stack overflow.
      Python runtime state: initialized

      Current thread 0x00007fab0bdda700 (most recent call first):
      File "/usr/local/python310/lib/python3.10/traceback.py", line 155 in _some_str
      File "/usr/local/python310/lib/python3.10/traceback.py", line 515 in __init__
      File "/usr/local/python310/lib/python3.10/traceback.py", line 103 in print_exception
      File "/usr/local/python310/lib/python3.10/traceback.py", line 163 in print_exc
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 4 in foo
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5 in foo
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5 in foo
      ...
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5 in foo
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5 in foo
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5 in foo
      File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5 in foo
      ...
      Aborted (core dumped)

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Dec 16, 2020
    3. changed the title [-]Title: Recursive traceback crashes Python Interpreter[/-] [+]Recursive traceback crashes Python Interpreter[/+] on Dec 17, 2020
    4. ronaldoussoren commented on Dec 17, 2020

      @ronaldoussoren
      Contributor

      This might be related to bpo-42500

    5. xxm commented on Dec 17, 2020

      xxmmannequin
      MannequinAuthor

      In issue#36272, they discuss a bug in logging module. They show an example which is similar as this one. So I think I think there might be a similar bug in traceback module.

    6. stestagg commented on Dec 17, 2020

      stestaggmannequin
      Mannequin

      Confirmed that bpo-42500 fixes this traceback, in commit 4e7a69b

      Parent commit:

      user@obsidian ~/t/f/cpython (master)> git checkout 93a0ef7
      Note: switching to '93a0ef7'.
      HEAD is now at 93a0ef7 Correct return type in Modules/_ssl.c::sslmodule_legacy (GH-23609)

      user@obsidian ~/t/f/cpython ((93a0ef7…))> ../test.sh
      + make distclean
      + CFLAGS=-O0
      + ./configure --prefix=/home/user/prefix --exec-prefix=/home/user/prefix --cache-file=../config.cache --with-pydebug --without-ensurepip
      + CFLAGS=-O0
      + make -j8 install
      /home/user/cpython/Lib/runpy.py:111: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
      __import__(pkg_name)
      /home/user/cpython/Lib/runpy.py:111: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
      __import__(pkg_name)
      ++ realpath /home/user/prefix/include/python3.10d/
      + INCLUDE_DIR=/home/user/prefix/include/python3.10d
      + set +e
      + PYTHONHOME=/home/user/prefix
      + /home/user/prefix/bin/python3 ../test.py
      NoneType: None
      ...
      NoneType: None
      Fatal Python error: _Py_CheckRecursiveCall: Cannot recover from stack overflow.
      Python runtime state: initialized

      Current thread 0x00007f483d4bd740 (most recent call first):
      File "/home/user/prefix/lib/python3.10/traceback.py", line 165 in _some_str
      File "/home/user/prefix/lib/python3.10/traceback.py", line 524 in __init__
      File "/home/user/prefix/lib/python3.10/traceback.py", line 113 in print_exception
      File "/home/user/prefix/lib/python3.10/traceback.py", line 173 in print_exc
      File "/home/user/cpython/../test.py", line 4 in foo
      ...
      ../test.sh: line 33: 50081 Aborted (core dumped) PYTHONHOME=$PREFIX $EPREFIX/bin/python3 ../test.py
      + [[ 134 -eq 139 ]]
      + exit 0

      After fix merged:

      user@obsidian ~/t/f/cpython ((93a0ef76…)) [1]> git checkout 4e7a69bdb6
      Previous HEAD position was 93a0ef7647 Correct return type in Modules/_ssl.c::sslmodule_legacy (GH-23609)
      HEAD is now at 4e7a69bdb6 bpo-42500: Fix recursion in or after except (GH-23568)
      user@obsidian ~/t/f/cpython ((4e7a69bd…))> ../test.sh
      + make distclean
      + CFLAGS=-O0
      + ./configure --prefix=/home/user/prefix --exec-prefix=/home/user/prefix --cache-file=../config.cache --with-pydebug --without-ensurepip
      + CFLAGS=-O0
      + make -j8 install
      /home/user/cpython/Lib/runpy.py:111: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
        __import__(pkg_name)
      /home/user/cpython/Lib/runpy.py:111: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
        __import__(pkg_name)
      ++ realpath /home/user/prefix/include/python3.10d/
      + INCLUDE_DIR=/home/user/prefix/include/python3.10d
      + set +e
      + PYTHONHOME=/home/user/prefix
      + /home/user/prefix/bin/python3 ../test.py
      NoneType: None
      ...
      NoneType: None
      Traceback (most recent call last):
        File "/home/user/prefix/lib/python3.10/traceback.py", line 165, in _some_str
          return str(value)
      RecursionError: maximum recursion depth exceeded while calling a Python object
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/home/user/cpython/../test.py", line 7, in <module>
          foo()
        File "/home/user/cpython/../test.py", line 5, in foo
          foo() 
        File "/home/user/cpython/../test.py", line 5, in foo
          foo() 
        File "/home/user/cpython/../test.py", line 5, in foo
          foo() 
        [Previous line repeated 989 more times]
        File "/home/user/cpython/../test.py", line 4, in foo
          traceback.print_exc()
        File "/home/user/prefix/lib/python3.10/traceback.py", line 173, in print_exc
          print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
        File "/home/user/prefix/lib/python3.10/traceback.py", line 113, in print_exception
          for line in TracebackException(
        File "/home/user/prefix/lib/python3.10/traceback.py", line 632, in format
          yield from self.format_exception_only()
        File "/home/user/prefix/lib/python3.10/traceback.py", line 580, in format_exception_only
          yield _format_final_exc_line(stype, self._str)
        File "/home/user/prefix/lib/python3.10/traceback.py", line 156, in _format_final_exc_line
          valuestr = _some_str(value)
        File "/home/user/prefix/lib/python3.10/traceback.py", line 167, in _some_str
          return '<unprintable %s object>' % type(value).__name__
      RecursionError: maximum recursion depth exceeded while calling a Python object
      + [[ 1 -eq 139 ]]
      + exit 0
    7. stestagg commented on Dec 17, 2020

      stestaggmannequin
      Mannequin

      Sorry, previous should have read "Fixes the abort"

    8. xxm commented on Dec 22, 2020

      xxmmannequin
      MannequinAuthor

      Thank you very much, looking forward to the new Python version.

      Could you please kindly change the resolution into fixed and close this issue?

    9. transferred this issue fromon Apr 10, 2022
    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.10 (EOL)end of life3.7 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions