Title: Segfault in `union_repr` from `list_repr_impl` in free-threaded build · Issue #132713 · python/cpython · GitHub
Open Graph Title: Segfault in `union_repr` from `list_repr_impl` in free-threaded build · Issue #132713 · python/cpython
X Title: Segfault in `union_repr` from `list_repr_impl` in free-threaded build · Issue #132713 · python/cpython
Description: Crash report What happened? Calling repr in many threads on a list containing a large typing.Union segfaults in a free-threaded build: import abc import builtins import collections.abc import itertools import types import typing from fun...
Open Graph Description: Crash report What happened? Calling repr in many threads on a list containing a large typing.Union segfaults in a free-threaded build: import abc import builtins import collections.abc import itert...
X Description: Crash report What happened? Calling repr in many threads on a list containing a large typing.Union segfaults in a free-threaded build: import abc import builtins import collections.abc import itert...
Opengraph URL: https://github.com/python/cpython/issues/132713
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Segfault in `union_repr` from `list_repr_impl` in free-threaded build","articleBody":"# Crash report\n\n### What happened?\n\nCalling `repr` in many threads on a list containing a large `typing.Union` segfaults in a free-threaded build:\n\n```python\nimport abc\nimport builtins\nimport collections.abc\nimport itertools\nimport types\nimport typing\nfrom functools import reduce\nfrom operator import or_\n\nabc_types = [cls for cls in abc.__dict__.values() if isinstance(cls, type)]\nbuiltins_types = [cls for cls in builtins.__dict__.values() if isinstance(cls, type)]\ncollections_abc_types = [cls for cls in collections.abc.__dict__.values() if isinstance(cls, type)]\ncollections_types = [cls for cls in collections.__dict__.values() if isinstance(cls, type)]\nitertools_types = [cls for cls in itertools.__dict__.values() if isinstance(cls, type)]\ntypes_types = [cls for cls in types.__dict__.values() if isinstance(cls, type)]\ntyping_types = [cls for cls in typing.__dict__.values() if isinstance(cls, type)]\n\nall_types = (abc_types + builtins_types + collections_abc_types + collections_types + itertools_types\n + types_types + typing_types)\nall_types = [t for t in all_types if not issubclass(t, BaseException)]\nBIG_UNION = reduce(or_, all_types, int)\n\nfrom threading import Thread\nfrom time import sleep\n\nfor x in range(100):\n union_list = [int | BIG_UNION] * 17 \n\n def stress_list():\n for x in range(3):\n try:\n union_list.pop()\n except Exception:\n pass\n repr(union_list)\n sleep(0.006)\n union_list.__getitem__(None, None)\n\n alive = []\n for x in range(25):\n alive.append(Thread(target=stress_list, args=()))\n\n for t in alive:\n t.start()\n```\n\nExample segfault backtrace:\n```\nThread 60 \"Thread-59 (stre\" received signal SIGSEGV, Segmentation fault.\n\n0x0000555555d21751 in _Py_TYPE (ob=\u003cunknown at remote 0xdddddddddddddddd>) at ./Include/object.h:270\n270 return ob->ob_type;\n\n#0 0x0000555555d21751 in _Py_TYPE (ob=\u003cunknown at remote 0xdddddddddddddddd>) at ./Include/object.h:270\n#1 union_repr (self=\u003coptimized out>) at Objects/unionobject.c:296\n#2 0x0000555555b8949a in PyObject_Repr (v=\u003cunknown at remote 0x7fffb48464b0>) at Objects/object.c:776\n#3 0x0000555555cc06a1 in PyUnicodeWriter_WriteRepr (writer=writer@entry=0x7fff660907f0,\n obj=\u003cunknown at remote 0x207c>) at Objects/unicodeobject.c:13951\n#4 0x0000555555aeba03 in list_repr_impl (v=0x7fffb4a8dc90) at Objects/listobject.c:606\n#5 list_repr (self=[]) at Objects/listobject.c:633\n#6 0x0000555555b8949a in PyObject_Repr (v=[]) at Objects/object.c:776\n#7 0x0000555555e07abf in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>,\n throwflag=\u003coptimized out>) at Python/generated_cases.c.h:2306\n#8 0x0000555555ddcf53 in _PyEval_EvalFrame (tstate=0x529000325210, frame=0x529000384328, throwflag=0)\n at ./Include/internal/pycore_ceval.h:119\n#9 _PyEval_Vector (tstate=0x529000325210, func=0x7fffb4828dd0, locals=0x0, args=\u003coptimized out>,\n argcount=1, kwnames=0x0) at Python/ceval.c:1917\n#10 0x0000555555a4f42b in _PyObject_VectorcallTstate (tstate=0x529000325210,\n callable=\u003cfunction at remote 0x7fffb4828dd0>, args=0x207c, nargsf=3, nargsf@entry=1,\n kwnames=\u003cunknown at remote 0x7fff66090450>, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#11 0x0000555555a4ccbf in method_vectorcall (method=\u003coptimized out>, args=\u003coptimized out>,\n nargsf=\u003coptimized out>, kwnames=\u003coptimized out>) at Objects/classobject.c:72\n#12 0x0000555555e8005b in _PyObject_VectorcallTstate (tstate=0x529000325210,\n callable=\u003cmethod at remote 0x7fff660c0eb0>, args=0x7fff93df06d8, nargsf=0, kwnames=0x0)\n at ./Include/internal/pycore_call.h:169\n#13 context_run (self=\u003c_contextvars.Context at remote 0x7fffb4a8ebf0>, args=\u003coptimized out>,\n nargs=\u003coptimized out>, kwnames=0x0) at Python/context.c:728\n#14 0x0000555555e0a3e7 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>,\n throwflag=\u003coptimized out>) at Python/generated_cases.c.h:3551\n```\n\nOnce it aborted with message:\n```\npython: Objects/unionobject.c:296: PyObject *union_repr(PyObject *): Assertion `PyTuple_Check(alias->args)' failed.\n```\n\nFound using [fusil](https://github.com/devdanzin/fusil) by @vstinner.\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.14.0a7+ experimental free-threading build (heads/main:741c6386b86, Apr 18 2025, 15:04:45) [Clang 19.1.7 (++20250114103320+cd708029e0b2-1~exp1~20250114103432.75)]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-132801\n* gh-132802\n* gh-132809\n* gh-132811\n* gh-132839\n* gh-132899\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2025-04-19T00:34:02Z","url":"https://github.com/python/cpython/issues/132713"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:ed3a8dc0-fea1-33b1-7140-78642ff716c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C348:2E124E:42B89FB:551989D:6B023AC0 |
| html-safe-nonce | a686d1d49d5f96dd2cbf226be8e2ceb99ec082fdd7df2a85bae25100be3500bf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzQ4OjJFMTI0RTo0MkI4OUZCOjU1MTk4OUQ6NkIwMjNBQzAiLCJ2aXNpdG9yX2lkIjoiMTY2MDIwNzc5MDMxNDEwOTYzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 996db4d8f4186fe7baee4e29b9ff19a97cb6de0bde35f8d0f5f641ca54ecac37 |
| hovercard-subject-tag | issue:3005995834 |
| 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/132713/issue_layout |
| twitter:image | https://opengraph.githubassets.com/931bacaee1f05ac8e3360a320e3a44850cf056f820bcc30e4156f63b9f4bc597/python/cpython/issues/132713 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/931bacaee1f05ac8e3360a320e3a44850cf056f820bcc30e4156f63b9f4bc597/python/cpython/issues/132713 |
| og:image:alt | Crash report What happened? Calling repr in many threads on a list containing a large typing.Union segfaults in a free-threaded build: import abc import builtins import collections.abc import itert... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdanzin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width