Skip to content

<unittest> AssertRaises() causes core dump in handling recursion #87351

Closed

Description

@CharlesFengY
BPO 43185
Nosy @terryjreedy, @markshannon, @iritkatriel, @CharlesFengY
Superseder
  • bpo-45806: Cannot Recover From StackOverflow in 3.9 Tests
  • 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/markshannon'
    closed_at = <Date 2021-11-19.18:15:58.815>
    created_at = <Date 2021-02-10.09:00:08.810>
    labels = ['interpreter-core', '3.9', 'type-crash']
    title = '<unittest> AssertRaises() causes core dump in handling recursion'
    updated_at = <Date 2021-11-19.18:15:58.815>
    user = 'https://github.com/CharlesFengY'

    bugs.python.org fields:

    activity = <Date 2021-11-19.18:15:58.815>
    actor = 'lukasz.langa'
    assignee = 'Mark.Shannon'
    closed = True
    closed_date = <Date 2021-11-19.18:15:58.815>
    closer = 'lukasz.langa'
    components = ['Interpreter Core']
    creation = <Date 2021-02-10.09:00:08.810>
    creator = 'CharlesFengY'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43185
    keywords = []
    message_count = 7.0
    messages = ['386763', '386775', '386776', '386777', '386778', '386779', '386910']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'Mark.Shannon', 'iritkatriel', 'CharlesFengY']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = '45806'
    type = 'crash'
    url = 'https://bugs.python.org/issue43185'
    versions = ['Python 3.9']

    Activity

    1. CharlesFengY commented on Feb 10, 2021

      CharlesFengYmannequin
      MannequinAuthor

      Seeing the following program, in the second assertRaises(), function "test_invalid_adpcm_state()" is recursively called. Then a fatal Python error shows up and the Python interpreter crashes.

      ++++++++++++++++++++++++++++++++++++++
      import unittest
      import audioop

      class TestAudioop(unittest.TestCase):
               pass
      
      def test_invalid_adpcm_state():
               TestAudioop.assertRaises(TypeError, audioop.lin2adpcm, b'\x00', 1, 555)
               TestAudioop.assertRaises(test_invalid_adpcm_state(), audioop.adpcm2lin, b'\x00', 1, (0, (- 1)))
      
      TestAudioop = TestAudioop()
      test_invalid_adpcm_state()

      +++++++++++++++++++++++++++++++++++++++

      System Info: Ubuntu 16.04
      Python Version: Python 3.9.1

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Feb 10, 2021
    3. iritkatriel commented on Feb 10, 2021

      @iritkatriel
      Member

      Reproduced on master as well. Simplified script:

      ------------------------------------------

      import unittest
      
      def f():
          raise TypeError
      
      class TestAudioop(unittest.TestCase):
          def test_invalid_adpcm_state(self):
              self.assertRaises(TypeError, f) 
              self.test_invalid_adpcm_state()

      TestAudioop().test_invalid_adpcm_state()

      ------------------------------------------

    4. CharlesFengY commented on Feb 10, 2021

      CharlesFengYmannequin
      MannequinAuthor

      Could you please tell me your secret method of getting the minimal script?
      I will try to provide minimal ones in our following work.

    5. markshannon commented on Feb 10, 2021

      @markshannon
      Member

      3.9 crashes.
      On master, I'm not seeing a crash, just a RecursionError.

      >>> import unittest
      >>> 
      >>> def f():
      ...     raise TypeError
      ... 
      >>> class TestAudioop(unittest.TestCase):
      ...     def test_invalid_adpcm_state(self):
      ...         self.assertRaises(TypeError, f) 
      ...         self.test_invalid_adpcm_state()
      ... 
      >>> TestAudioop().test_invalid_adpcm_state()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "<stdin>", line 4, in test_invalid_adpcm_state
        File "<stdin>", line 4, in test_invalid_adpcm_state
        File "<stdin>", line 4, in test_invalid_adpcm_state
        [Previous line repeated 992 more times]
        File "<stdin>", line 3, in test_invalid_adpcm_state
        File "/home/mark/repos/cpython/Lib/unittest/case.py", line 730, in assertRaises
          context = _AssertRaisesContext(expected_exception, self)
        File "/home/mark/repos/cpython/Lib/unittest/case.py", line 168, in __init__
          _BaseTestCaseContext.__init__(self, test_case)
      RecursionError: maximum recursion depth exceeded
    6. iritkatriel commented on Feb 10, 2021

      @iritkatriel
      Member

      Yang - no secret really, just trial and error.
      Mark - right I wasn't on master, sorry.

    7. markshannon commented on Feb 10, 2021

      @markshannon
      Member

      I think this was fixed by #23568

      The root cause seems to be the same as bpo-42500, so I'm going to backport #23568 to 3.9

    8. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 10, 2021
    9. self-assigned this
      on Feb 10, 2021
    10. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 10, 2021
    11. self-assigned this
      on Feb 10, 2021
    12. terryjreedy commented on Feb 13, 2021

      @terryjreedy
      Member

      bpo-43186, bpo-43187 also have recursive code that fails in 3.9 and recovers in 3.10. Am closing them in favor of this. Also suspect bpo-43188, bpo-43189, bpo-43190 are duplicates. Yang, recheck after Mark does the backport here.

    13. 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

    Labels

    3.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