Title: Race in `Thread.join()` · Issue #116372 · python/cpython · GitHub
Open Graph Title: Race in `Thread.join()` · Issue #116372 · python/cpython
X Title: Race in `Thread.join()` · Issue #116372 · python/cpython
Description: Bug report Bug description: There is a race between when Thread._tstate_lock is released1 in Thread._wait_for_tstate_lock() and when Thread._stop() asserts2 that it is unlocked. Consider the following execution involving threads A, B, an...
Open Graph Description: Bug report Bug description: There is a race between when Thread._tstate_lock is released1 in Thread._wait_for_tstate_lock() and when Thread._stop() asserts2 that it is unlocked. Consider the follow...
X Description: Bug report Bug description: There is a race between when Thread._tstate_lock is released1 in Thread._wait_for_tstate_lock() and when Thread._stop() asserts2 that it is unlocked. Consider the follow...
Opengraph URL: https://github.com/python/cpython/issues/116372
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Race in `Thread.join()`","articleBody":"# Bug report\n\n### Bug description:\n\nThere is a race between when `Thread._tstate_lock` is released[^1] in `Thread._wait_for_tstate_lock()` and when `Thread._stop()` asserts[^2] that it is unlocked. Consider the following execution involving threads A, B, and C:\n\n1. A starts.\n2. B joins A, blocking on its `_tstate_lock`.\n3. C joins A, blocking on its `_tstate_lock`.\n4. A finishes and releases its `_tstate_lock`.\n5. B acquires A's `_tstate_lock` in `_wait_for_tstate_lock()`, releases it, but is swapped out before calling `_stop()`.\n6. C is scheduled, acquires A's `_tstate_lock` in `_wait_for_tstate_lock()` but is swapped out before releasing it.\n7. B is scheduled, calls `_stop()`, which asserts that A's `_tstate_lock` is not held. However, C holds it, so the assertion fails.\n\nThe race can be reproduced[^3] by inserting sleeps at the appropriate points in the threading code. To do so, run the `repro_join_race.py` from the linked repo.\n\n[^1]: https://github.com/python/cpython/blob/441affc9e7f419ef0b68f734505fa2f79fe653c7/Lib/threading.py#L1201\n[^2]: https://github.com/python/cpython/blob/441affc9e7f419ef0b68f734505fa2f79fe653c7/Lib/threading.py#L1115\n[^3]: https://github.com/mpage/cpython/commit/81946532792f938cd6f6ab4c4ff92a4edf61314f\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/mpage","@type":"Person","name":"mpage"},"datePublished":"2024-03-05T17:31:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/116372/cpython/issues/116372"}
| 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:2ceedc29-7d8c-620b-e47a-00c9334a8930 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9826:1672C1:FA7A78:1476936:696B0AA5 |
| html-safe-nonce | 7c900b9b2d8cb31f5df057737e44b7fd1a827a9c2b1904d23eb52c4b1d42ac3e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODI2OjE2NzJDMTpGQTdBNzg6MTQ3NjkzNjo2OTZCMEFBNSIsInZpc2l0b3JfaWQiOiI1NTY1OTkxMzkyMTc0MDgyNzI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4f518a25c9d83250ddbf474fd3e91582574650f95fc3297f4b409600c93e1108 |
| hovercard-subject-tag | issue:2169782711 |
| 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/116372/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb35468f1cc7bc2136edcdf381dcd2be4454e7992e65e09db826086131c674a8/python/cpython/issues/116372 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb35468f1cc7bc2136edcdf381dcd2be4454e7992e65e09db826086131c674a8/python/cpython/issues/116372 |
| og:image:alt | Bug report Bug description: There is a race between when Thread._tstate_lock is released1 in Thread._wait_for_tstate_lock() and when Thread._stop() asserts2 that it is unlocked. Consider the follow... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mpage |
| 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