Repository navigation
Errors during array module import result in double-DECREF #153210
Copy link
Copy link
Closed
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
- addedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on Jul 6, 2026 Indeed, I also found several other problems with the setup. I will send a PR, thanks for the report! 👍
- addedextension-modulesC modules in the Modules dirC modules in the Modules dir
on Jul 6, 2026 @sobolevn Haha, we got there at the same time :), I'll withdraw mine
Reacted by sobolevn@sobolevn I'm seeing failures with
from array import ArrayType: https://github.com/coveragepy/coveragepy/actions/runs/28859740335It also happens with newly built main:
% /usr/local/cpython/bin/python3.16 Python 3.16.0a0 (heads/main:2cd5b79284d, Jul 7 2026, 07:09:41) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from array import ArrayType Traceback (most recent call last): File "<python-input-0>", line 1, in <module> from array import ArrayType ImportError: cannot import name 'ArrayType' from 'array' (/usr/local/cpython/lib/python3.16/lib-dynload/array.cpython-316-darwin.so)Building from the commit before this fix:
% /usr/local/cpython/bin/python3.16 Python 3.16.0a0 (tags/v3.15.0b1-901-g35c6779c7b5:35c6779c7b5, Jul 7 2026, 07:35:22) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from array import ArrayType >>>@nedbat thanks for the report! on it :)
- added 5 commits that reference this issue
on Jul 7, 2026 - moved this to Todo in Struct, memoryview and array issues 🏗️
on Jul 13, 2026 - moved this from Todo to Done in Struct, memoryview and array issues 🏗️
on Jul 13, 2026
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Projects
- StatusShow more project fieldsDone
Crash report
What happened?
In DEBUG build:
or:
generates a double DECREF on the array
ArrayTypeobject due to poisoned module state:Analysis
So,
array_modexeccreates theArrayTypeand assigns it to array state:cpython/Modules/arraymodule.c
Line 3400 in 836b206
It then goes on to do some other setup tasks, and if any of these fail, it DECREF's
state->ArrayTypebut leaves the type object on the state struct:cpython/Modules/arraymodule.c
Lines 3409 to 3421 in 836b206
Returning
-1error code.PyModule_ExecDefpasses the -1 up the chain:cpython/Objects/moduleobject.c
Line 793 in 0514489
which ends up with an exception in _bootstrap.py:
cpython/Lib/importlib/_bootstrap.py
Lines 910 to 915 in 0514489
At this point, the array module refcount falls and it's cleaned up, and
array_clearcalls:cpython/Modules/arraymodule.c
Line 3346 in 2d7a74e
because the
ArrayTypepointer is still in the modulestate, this generates the double DECREFCPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.16.0a0 (heads/main-dirty:1034e73, Jul 6 2026, 11:11:46) [Clang 22.1.6 ]
Linked PRs
arraymodule import crash under a memory pressure #153238arraymodule import crash under a memory pressure (GH-153238) #153249arraymodule import crash under a memory pressure (GH-153238) #153250arraymodule import crash under a memory pressure (GH-153238) #153251array.ArrayTyperemoval #153261array.ArrayTyperemoval (GH-153261) #153274array.ArrayTyperemoval (GH-153261) #153275array.ArrayTyperemoval (GH-153261) #153289