Title: Free-threading QSBR delayed free mem fails in high thread turnover environment · Issue #130794 · python/cpython · GitHub
Open Graph Title: Free-threading QSBR delayed free mem fails in high thread turnover environment · Issue #130794 · python/cpython
X Title: Free-threading QSBR delayed free mem fails in high thread turnover environment · Issue #130794 · python/cpython
Description: Crash report What happened? When cycling a lot of threads and modifying objects which use PyMem_FreeDelayed() in those threads the queues of memory blocks to free build up without ever being freed until the process runs out of memory, un...
Open Graph Description: Crash report What happened? When cycling a lot of threads and modifying objects which use PyMem_FreeDelayed() in those threads the queues of memory blocks to free build up without ever being freed ...
X Description: Crash report What happened? When cycling a lot of threads and modifying objects which use PyMem_FreeDelayed() in those threads the queues of memory blocks to free build up without ever being freed ...
Opengraph URL: https://github.com/python/cpython/issues/130794
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Free-threading QSBR delayed free mem fails in high thread turnover environment","articleBody":"# Crash report\n\n### What happened?\n\nWhen cycling a lot of threads and modifying objects which use `PyMem_FreeDelayed()` in those threads the queues of memory blocks to free build up without ever being freed until the process runs out of memory, unless something else causes them to be freed. For example in the reproducer below commenting in the `gc.collect()` or the `for` loop will cause the delayed blocks to be freed correctly. Note that this is an extreme case.\n\nReproducer:\n```python\nimport gc\nimport threading\n\n\ndef fupmem(b, l):\n b.wait()\n l *= 2\n\n\ndef check(funcs, *args):\n barrier = threading.Barrier(len(funcs))\n thrds = []\n\n for func in funcs:\n thrd = threading.Thread(target=func, args=(barrier, *args))\n\n thrds.append(thrd)\n thrd.start()\n\n for thrd in thrds:\n thrd.join()\n\n\nif __name__ == \"__main__\":\n count = 0\n\n while True:\n print(count := count + 1)\n\n check([fupmem] * 10, [None] * 256)\n\n # gc.collect()\n\n # for i in range(1000):\n # l = []\n # del l\n```\n\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.14.0a5+ experimental free-threading build (heads/main:b3c18bfd828, Mar 3 2025, 09:13:46) [GCC 11.4.0]\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-130808\n* gh-130857\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/tom-pytel","@type":"Person","name":"tom-pytel"},"datePublished":"2025-03-03T14:15:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/130794/cpython/issues/130794"}
| 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:fd96cdfa-47dc-ce21-651b-bec23f4314f4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94C2:6F7C:B6E10E:F28024:696B59A4 |
| html-safe-nonce | 6f3aba9521f8ba2d9b2ee7bc518e38e09dfb3b79200c115a8b437e7952c1e4ac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEMyOjZGN0M6QjZFMTBFOkYyODAyNDo2OTZCNTlBNCIsInZpc2l0b3JfaWQiOiI4MzIzNjk2OTMyNjYzNTQ4MzI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7290417914b83ea7e8edd0e11d6f52dbe7b7283b596be70b159284b492529a33 |
| hovercard-subject-tag | issue:2891375681 |
| 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/130794/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a7b27c7d429888a9a45d8f5a5043f852774100d2d25b95158d00c1fa9c80c868/python/cpython/issues/130794 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a7b27c7d429888a9a45d8f5a5043f852774100d2d25b95158d00c1fa9c80c868/python/cpython/issues/130794 |
| og:image:alt | Crash report What happened? When cycling a lot of threads and modifying objects which use PyMem_FreeDelayed() in those threads the queues of memory blocks to free build up without ever being freed ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tom-pytel |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width