This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: multiple operations of dict causes core dump of Python interpreter.
Type: crash Stage:
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: CharlesFengY, methane, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2021-02-10 09:44 by CharlesFengY, last changed 2022-04-11 14:59 by admin.

Messages (4)
msg386766 - (view) Author: Yang Feng (CharlesFengY) Date: 2021-02-10 09:44
In the following programs, we call check_reentrant_insertion("s") twice,  after multiple of update and clear of dict, the Python interpreter crashes.
+++++++++++++++++++++++++++++++++++++++++++
def check_reentrant_insertion(mutate):

        class Mutating:
            def __del__(self):
                mutate(d)

        d = {k: Mutating() for k in 'abcdefghijklmnopqr'}
        for k in list(d):
            d[k] = k

def test_reentrant_insertion():

    check_reentrant_insertion("s")

    def mutate(d):
        d.update(DictTest.__dict__)
        d.clear()
    check_reentrant_insertion(test_reentrant_insertion())

test_reentrant_insertion()
+++++++++++++++++++++++++++++++++++++++++

System Info: Ubuntu 16.04
Python Version:  Python 3.9.1
msg386811 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-02-10 21:44
I can confirm this crashes.
msg386812 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-02-10 21:51
Is this the crash you are reporting?

```
Exception ignored in: <function check_reentrant_insertion.<locals>.Mutating.__del__ at 0x100d35af0>
Traceback (most recent call last):
  File "/Users/methane/work/python/cpython/PC/xxx.py", line 5, in __del__
    mutate(d)
TypeError: 'str' object is not callable
Exception ignored in: <function check_reentrant_insertion.<locals>.Mutating.__del__ at 0x100d35c10>
Traceback (most recent call last):
  File "/Users/methane/work/python/cpython/PC/xxx.py", line 5, in __del__
Fatal Python error: _Py_CheckRecursiveCall: Cannot recover from stack overflow.
Python runtime state: initialized

Current thread 0x000000010072bd40 (most recent call first):
  File "/Users/methane/work/python/cpython/xxx.py", line 9 in check_reentrant_insertion
  File "/Users/methane/work/python/cpython/xxx.py", line 13 in test_reentrant_insertion
  File "/Users/methane/work/python/cpython/xxx.py", line 18 in test_reentrant_insertion
...
```
msg386907 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-02-13 05:07
Like the code in #43185, #43186, #43187, this works better in 3.10.0a5, so I suspect it is another duplicate.
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87354
2021-02-13 05:07:49terry.reedysetnosy: + terry.reedy
messages: + msg386907
2021-02-10 21:51:08methanesetmessages: + msg386812
2021-02-10 21:44:32rhettingersetnosy: + rhettinger, methane
messages: + msg386811
2021-02-10 09:44:21CharlesFengYcreate