Title: Segfault or abort in free-threaded build calling methods from exception in threads · Issue #127192 · python/cpython · GitHub
Open Graph Title: Segfault or abort in free-threaded build calling methods from exception in threads · Issue #127192 · python/cpython
X Title: Segfault or abort in free-threaded build calling methods from exception in threads · Issue #127192 · python/cpython
Description: Crash report What happened? In a no-gil build with PYTHON_GIL=0, it's possible to get the interpreter to segfault or abort with the message Fatal Python error: PyMutex_Unlock: unlocking mutex that is not locked by running the following c...
Open Graph Description: Crash report What happened? In a no-gil build with PYTHON_GIL=0, it's possible to get the interpreter to segfault or abort with the message Fatal Python error: PyMutex_Unlock: unlocking mutex that ...
X Description: Crash report What happened? In a no-gil build with PYTHON_GIL=0, it's possible to get the interpreter to segfault or abort with the message Fatal Python error: PyMutex_Unlock: unlocking mutex t...
Opengraph URL: https://github.com/python/cpython/issues/127192
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Segfault or abort in free-threaded build calling methods from exception in threads","articleBody":"# Crash report\n\n### What happened?\n\nIn a no-gil build with `PYTHON_GIL=0`, it's possible to get the interpreter to segfault or abort with the message `Fatal Python error: PyMutex_Unlock: unlocking mutex that is not locked` by running the following code:\n\n```python\nfrom threading import Thread\nimport email.errors\n\nalive = []\nfor x in range(100):\n obj = email.errors.InvalidMultipartContentTransferEncodingDefect()\n\n alive.append(Thread(target=obj.__getstate__, args=()))\n alive.append(Thread(target=obj.__repr__, args=()))\n for x in range(20):\n obj.__init__([\"a\" * (2 ** 16)])\n alive.append(Thread(target=obj.__init__, args=([\"a\" * (2 ** 16)],)))\n\nfor obj in alive:\n try:\n print('START', obj)\n obj.start()\n except Exception:\n pass\n```\nSomehow it seems very hard to trigger a segfault under gdb, so here's the backtrace from the abort:\n```gdb\n#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=140736531846720) at ./nptl/pthread_kill.c:44\n#1 __pthread_kill_internal (signo=6, threadid=140736531846720) at ./nptl/pthread_kill.c:78\n#2 __GI___pthread_kill (threadid=140736531846720, signo=signo@entry=6) at ./nptl/pthread_kill.c:89\n#3 0x00007ffff7ce0476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\n#4 0x00007ffff7cc67f3 in __GI_abort () at ./stdlib/abort.c:79\n#5 0x0000555555944db0 in fatal_error_exit (status=\u003coptimized out>) at Python/pylifecycle.c:3059\n#6 0x00005555559519fb in fatal_error (fd=2, header=header@entry=1,\n prefix=prefix@entry=0x555555b0bb20 \u003c__func__.0> \"PyMutex_Unlock\",\n msg=msg@entry=0x555555b0b950 \"unlocking mutex that is not locked\", status=status@entry=-1)\n at Python/pylifecycle.c:3275\n#7 0x0000555555951a6d in _Py_FatalErrorFunc (\n func=func@entry=0x555555b0bb20 \u003c__func__.0> \"PyMutex_Unlock\",\n msg=msg@entry=0x555555b0b950 \"unlocking mutex that is not locked\") at Python/pylifecycle.c:3291\n#8 0x000055555592a36f in PyMutex_Unlock (m=\u003coptimized out>) at Python/lock.c:615\n#9 0x00005555556c6e23 in _PyMutex_Unlock (m=\u003coptimized out>) at ./Include/cpython/lock.h:60\n#10 _PyCriticalSection_End (c=0x7fffc6fcc5f0) at ./Include/internal/pycore_critical_section.h:148\n#11 list_repr (self=\u003coptimized out>) at Objects/listobject.c:581\n#12 0x0000555555709951 in PyObject_Repr (\n v=[\u003cunknown at remote 0xdddddddddddddddd>, \u003cunknown at remote 0xdddddddddddddddd>, \u003cunknown at remote 0xdddddddddddddddd>, \u003cunknown at remote 0xdddddddddddddddd>]) at Objects/object.c:737\n#13 0x00005555557accbf in unicode_fromformat_arg (writer=writer@entry=0x7fffc6fcc750,\n f=0x555555a590bc \"R)\", f@entry=0x555555a590bb \"%R)\", vargs=vargs@entry=0x7fffc6fcc700)\n at Objects/unicodeobject.c:3048\n#14 0x00005555557ad0dd in unicode_from_format (writer=writer@entry=0x7fffc6fcc750,\n format=format@entry=0x555555a590b8 \"%s(%R)\", vargs=vargs@entry=0x7fffc6fcc7c0)\n at Objects/unicodeobject.c:3167\n#15 0x00005555557ad287 in PyUnicode_FromFormatV (format=0x555555a590b8 \"%s(%R)\",\n vargs=vargs@entry=0x7fffc6fcc7c0) at Objects/unicodeobject.c:3201\n#16 0x00005555557ad363 in PyUnicode_FromFormat (format=format@entry=0x555555a590b8 \"%s(%R)\") at Objects/unicodeobject.c:3215\n#17 0x00005555556986fb in BaseException_repr (self=self@entry=0x200005d2aa0) at Objects/exceptions.c:170\n#18 0x000055555574c3f3 in wrap_unaryfunc (self=\u003cInvalidMultipartContentTransferEncodingDefect(line=['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...(truncated), args=\u003coptimized out>, wrapped=0x555555698672 \u003cBaseException_repr>) at Objects/typeobject.c:8947\n#19 0x0000555555691ce5 in wrapperdescr_raw_call (kwds={}, args=(), self=\u003coptimized out>, descr=\u003coptimized out>) at Objects/descrobject.c:531\n#20 wrapper_call (self=self@entry=\u003cmethod-wrapper '__repr__' of InvalidMultipartContentTransferEncodingDefect object at 0x200005d2aa0>, args=args@entry=(), kwds=kwds@entry={}) at Objects/descrobject.c:1438\n#21 0x000055555567f6ef in _PyObject_Call (tstate=0x555555dd7700, callable=callable@entry=\u003cmethod-wrapper '__repr__' of InvalidMultipartContentTransferEncodingDefect object at 0x200005d2aa0>, args=args@entry=(), kwargs=kwargs@entry={}) at Objects/call.c:361\n#22 0x000055555567f811 in PyObject_Call (callable=callable@entry=\u003cmethod-wrapper '__repr__' of InvalidMultipartContentTransferEncodingDefect object at 0x200005d2aa0>, args=args@entry=(), kwargs=kwargs@entry={}) at Objects/call.c:373\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.0a2+ experimental free-threading build (heads/main-dirty:a13e94d84bf, Nov 23 2024, 07:16:19) [GCC 11.4.0]","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2024-11-23T11:57:33Z","url":"https://github.com/python/cpython/issues/127192"}
| 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:3360b3f1-cd2b-15db-7cea-c26b11382c85 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A5C6:2E7DFB:69E98F:8B0B14:6B024B35 |
| html-safe-nonce | 91abc1623a67b2ab10cbde1a603fbd03baf8e0e9c74400ffa6778734e55cccf2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUM2OjJFN0RGQjo2OUU5OEY6OEIwQjE0OjZCMDI0QjM1IiwidmlzaXRvcl9pZCI6IjM3OTM1NzYzMDc0Njg2ODQwODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 95f01db9cd401564dbf2e5f34ba80b24688112fca9cd2c6aadbb5dd647a89164 |
| hovercard-subject-tag | issue:2685921773 |
| 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/127192/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f617cffd140f8715a496c457183dc6c12dc17263bc8ea420c5c3c2b25de29fca/python/cpython/issues/127192 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f617cffd140f8715a496c457183dc6c12dc17263bc8ea420c5c3c2b25de29fca/python/cpython/issues/127192 |
| og:image:alt | Crash report What happened? In a no-gil build with PYTHON_GIL=0, it's possible to get the interpreter to segfault or abort with the message Fatal Python error: PyMutex_Unlock: unlocking mutex that ... |
| 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