Title: test_capi fails on Sanitizers / TSan (free-threading) CI with exit code 66 · Issue #162144 · python/cpython · GitHub
Open Graph Title: test_capi fails on Sanitizers / TSan (free-threading) CI with exit code 66 · Issue #162144 · python/cpython
X Title: test_capi fails on Sanitizers / TSan (free-threading) CI with exit code 66 · Issue #162144 · python/cpython
Description: Bug report It seems like the problem comes from test_object_clear_managed_dict_ft_memory_error() of test_capi.test_object, a test added 2 days ago (commit 369d8bc). I don't think that the problem comes from this specific test, but more f...
Open Graph Description: Bug report It seems like the problem comes from test_object_clear_managed_dict_ft_memory_error() of test_capi.test_object, a test added 2 days ago (commit 369d8bc). I don't think that the problem c...
X Description: Bug report It seems like the problem comes from test_object_clear_managed_dict_ft_memory_error() of test_capi.test_object, a test added 2 days ago (commit 369d8bc). I don't think that the probl...
Opengraph URL: https://github.com/python/cpython/issues/162144
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_capi fails on Sanitizers / TSan (free-threading) CI with exit code 66","articleBody":"### Bug report\n\nIt seems like the problem comes from `test_object_clear_managed_dict_ft_memory_error()` of test_capi.test_object, a test added 2 days ago (commit 369d8bc4f6fe1f751de2512523a1acb95491a5eb).\n\nI don't think that the problem comes from this specific test, but more from `_testcapi.set_nomemory()` and `_testcapi.call_with_nomemory()` which are **not** thread safe. The problem comes from `PyMem_SetAllocator()` which uses a lock whereas functions reading the allocation function don't use a lock.\n\nI suppose that `@support.nomemtest` should be modified to skip the test if TSan is used.\n\nI'm working on a fix.\n\n---\n\nPython built with `./configure --config-cache 'OPT=-O2 -g' --with-thread-sanitizer --with-pydebug --disable-gil CC=clang LD=clang`.\n\nTest: `TSAN_OPTIONS=\"log_path=$PWD/san_log handle_segv=0\" ./python -m test test_capi --matchfile=bisect -v; echo \"exitcode => $?\"`.\n\nThe command fails with exit code 66.\n\nWith `bisect` file:\n\n```\ntest.test_capi.test_abstract.CAPITest.test_mapping_haskeystring\ntest.test_capi.test_capsule.CapsuleImportTests.test_error_from_import\ntest.test_capi.test_complex.CAPIComplexTest.test_py_c_pow\ntest.test_capi.test_config.CAPITests.test_config_set_cpu_count\ntest.test_capi.test_exceptions.Test_PyUnstable_Exc_PrepReraiseStar.test_reraise_orig\ntest.test_capi.test_function.FunctionTest.test_function_get_module\ntest.test_capi.test_getargs.Bytes_TestCase.test_c\ntest.test_capi.test_getargs.Bytes_TestCase.test_w_star\ntest.test_capi.test_mem.PyMemMallocDebugTests.test_pyobject_freed_is_freed\ntest.test_capi.test_misc.Test_testcapi.test_atomic_exchange_uint64\ntest.test_capi.test_misc.Test_testcapi.test_buildvalue_N\ntest.test_capi.test_misc.Test_testcapi.test_dict_iteration\ntest.test_capi.test_misc.Test_testcapi.test_pythread_tss_key_state\ntest.test_capi.test_object.CAPITest.test_object_clear_managed_dict_ft_memory_error\ntest.test_capi.test_slots.TypeSlotsTests.test_repeat_warning\ntest.test_capi.test_type.BuiltinStaticTypesTests.test_tp_bases_is_set\ntest.test_capi.test_unicode.CAPITest.test_fromstring\ntest.test_capi.test_unicode.CAPITest.test_tailmatch\ntest.test_capi.test_watchers.TestDictWatchers.test_watch_unassigned_watcher_id\ntest.test_capi.test_weakref.CAPIWeakrefTest.test_pyweakref_checkproxy\n```\n\nTSan log:\n\n```\nWARNING: ThreadSanitizer: data race (pid=2260396)\n Write of size 8 at 0x000000dee638 by thread T13:\n #0 __tsan_memcpy ??:? (python+0x760682) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n #1 set_allocator_unlocked /home/vstinner/python/main/Objects/obmalloc.c:? (python+0x9fec80) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n #2 PyMem_SetAllocator /home/vstinner/python/main/Objects/obmalloc.c:1152 (python+0x9fec80)\n #3 fm_setup_hooks /home/vstinner/python/main/./Modules/_testcapi/mem.c:163 (_testcapi.cpython-316td-x86_64-linux-gnu.so+0x52303) (BuildId: 0eac47155c6133af464962558ffdbdb649d9b928)\n #4 fm_set_nomemory /home/vstinner/python/main/./Modules/_testcapi/mem.c:189 (_testcapi.cpython-316td-x86_64-linux-gnu.so+0x52303)\n #5 call_with_nomemory /home/vstinner/python/main/./Modules/_testcapi/mem.c:239 (_testcapi.cpython-316td-x86_64-linux-gnu.so+0x511b1) (BuildId: 0eac47155c6133af464962558ffdbdb649d9b928)\n ...\n\n Previous read of size 8 at 0x000000dee638 by main thread:\n #0 PyMem_Malloc /home/vstinner/python/main/Objects/obmalloc.c:1266 (python+0x9ff062) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n #1 list_allocate_array /home/vstinner/python/main/Objects/listobject.c:42 (python+0x957c14) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n #2 py_list_resize /home/vstinner/python/main/Objects/listobject.c:163 (python+0x957c14)\n #3 list_resize /home/vstinner/python/main/Objects/listobject.c:128 (python+0x957c14)\n #4 _PyList_AppendTakeRefListResize /home/vstinner/python/main/Objects/listobject.c:586 (python+0x957923) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n #5 _PyList_AppendTakeRef /home/vstinner/python/main/./Include/internal/pycore_list.h:53 (python+0xb4eb97) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n #6 _PyEval_EvalFrameDefault /home/vstinner/python/main/Python/generated_cases.c.h:3984 (python+0x7061fe) (BuildId: 088d0863e8351f5ea2fa99217aa4430d2048d6e2)\n ...\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-162154\n* gh-162174\n* gh-162175\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2026-11-17T01:02:07Z","url":"https://github.com/python/cpython/issues/162144"}
| 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:d1fdf8ce-2d59-28a0-c7c8-dccd30ed2a70 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A01E:A70A9:1301711:1925116:6B01EE01 |
| html-safe-nonce | 4ebf94a44b74a9c13cf643921681b3c705e2558e93d3d5dcba75c8e7e046f695 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDFFOkE3MEE5OjEzMDE3MTE6MTkyNTExNjo2QjAxRUUwMSIsInZpc2l0b3JfaWQiOiIzMDg5MjkxNTMwMjMwNDI3MTM3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e644ec668c560b5b9b29916934c61778de3c9729aa8d7aaac51c9d7d114746c8 |
| hovercard-subject-tag | issue:6434466878 |
| 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/162144/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cbc0c84af404c6bc645d37119b6fb76f163962736811965d73f19a3e9ceba6ba/python/cpython/issues/162144 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cbc0c84af404c6bc645d37119b6fb76f163962736811965d73f19a3e9ceba6ba/python/cpython/issues/162144 |
| og:image:alt | Bug report It seems like the problem comes from test_object_clear_managed_dict_ft_memory_error() of test_capi.test_object, a test added 2 days ago (commit 369d8bc). I don't think that the problem c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| 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