Title: Errors during `array` module import result in double-DECREF · Issue #153210 · python/cpython · GitHub
Open Graph Title: Errors during `array` module import result in double-DECREF · Issue #153210 · python/cpython
X Title: Errors during `array` module import result in double-DECREF · Issue #153210 · python/cpython
Description: Crash report What happened? In DEBUG build: import collections.abc del collections.abc.MutableSequence import array or: sys.setrecursionlimit(25) import array generates a double DECREF on the array ArrayType object due to poisoned module...
Open Graph Description: Crash report What happened? In DEBUG build: import collections.abc del collections.abc.MutableSequence import array or: sys.setrecursionlimit(25) import array generates a double DECREF on the array...
X Description: Crash report What happened? In DEBUG build: import collections.abc del collections.abc.MutableSequence import array or: sys.setrecursionlimit(25) import array generates a double DECREF on the array...
Opengraph URL: https://github.com/python/cpython/issues/153210
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Errors during `array` module import result in double-DECREF","articleBody":"# Crash report\n\n### What happened?\n\nIn DEBUG build:\n```python\nimport collections.abc\n\ndel collections.abc.MutableSequence\nimport array\n```\nor:\n```\nsys.setrecursionlimit(25)\nimport array\n```\n\ngenerates a double DECREF on the array `ArrayType` object due to poisoned module state:\n\n```text\nPython/gc.c:96: gc_decref: Assertion \"gc_get_refs(g) \u003e 0\" failed: refcount is too small\nobject type name: type\nobject repr : \u003cclass 'array.array'\u003e\nFatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed\n```\n\n### Analysis\n\nSo, `array_modexec` creates the `ArrayType` and assigns it to array state:\nhttps://github.com/python/cpython/blob/836b2069c86e25cf9456e9210bb612e5166d0779/Modules/arraymodule.c#L3400\n\n It then goes on to do some other setup tasks, and if any of these fail, it DECREF's `state-\u003eArrayType` but leaves the type object on the state struct:\n\nhttps://github.com/python/cpython/blob/836b2069c86e25cf9456e9210bb612e5166d0779/Modules/arraymodule.c#L3409-L3421\n\nReturning `-1` error code.\n\n`PyModule_ExecDef` passes the -1 up the chain:\nhttps://github.com/python/cpython/blob/0514489372f24e8ada518c82ab246de6a22aa3f7/Objects/moduleobject.c#L793\nwhich ends up with an exception in _bootstrap.py:\nhttps://github.com/python/cpython/blob/0514489372f24e8ada518c82ab246de6a22aa3f7/Lib/importlib/_bootstrap.py#L910-L915\n\nAt this point, the array module refcount falls and it's cleaned up, and `array_clear` calls:\nhttps://github.com/python/cpython/blob/2d7a74ece7884c9a5f52cc6ac38a6e7ee691b26c/Modules/arraymodule.c#L3346\nbecause the `ArrayType` pointer is still in the module `state`, this generates the double DECREF\n\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.16.0a0 (heads/main-dirty:1034e73, Jul 6 2026, 11:11:46) [Clang 22.1.6 ]\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-153238\n* gh-153239\n* gh-153249\n* gh-153250\n* gh-153251\n* gh-153261\n* gh-153274\n* gh-153275\n* gh-153289\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/stestagg","@type":"Person","name":"stestagg"},"datePublished":"2026-07-06T14:57:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/153210/cpython/issues/153210"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:130dce28-f825-9c96-898a-038e5b000c9e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9026:B319:2C900B:3C7BFC:6A52E89C |
| html-safe-nonce | 169b8c0ec5209f7048024ec26ee0876e5928f7241b21c565664d96f691a3961b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDI2OkIzMTk6MkM5MDBCOjNDN0JGQzo2QTUyRTg5QyIsInZpc2l0b3JfaWQiOiI4NjQ0MDk2NzU5OTA2MzYzNTQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | eba60fdb12a735365ef22ed288958948c1aef010e5e572d7004714a273cd9495 |
| hovercard-subject-tag | issue:4820340091 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/153210/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b38b7e9a1d2d621920f99de3fbe5b352ae1fda25f80c36b641a38e76672f6a5/python/cpython/issues/153210 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b38b7e9a1d2d621920f99de3fbe5b352ae1fda25f80c36b641a38e76672f6a5/python/cpython/issues/153210 |
| og:image:alt | Crash report What happened? In DEBUG build: import collections.abc del collections.abc.MutableSequence import array or: sys.setrecursionlimit(25) import array generates a double DECREF on the array... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stestagg |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width