Title: gh-132942: Fix races in type lookup cache by nascheme · Pull Request #133032 · python/cpython · GitHub
Open Graph Title: gh-132942: Fix races in type lookup cache by nascheme · Pull Request #133032 · python/cpython
X Title: gh-132942: Fix races in type lookup cache by nascheme · Pull Request #133032 · python/cpython
Description: Two races related to the type lookup cache, when used in the free-threaded build. This caused test_opcache to sometimes fail (as well as other hard to reproduce failures). The first problem is that find_name_in_mro() can block on some mutex and then release critical sections. If that happens, the type version used for the cache entry can be wrong (too new). Assigning the version before doing the find fixes this issue. If it does race, you will add an entry that uses an out-of-date version. The second problem was much harder to track down. There is a hard to trigger race in update_cache(), writing to cache, and _PyType_LookupStackRefAndVersion(), reading from cache. We use a sequence lock to avoid races. However, if the reader reads the old entry value and the new entry version, it will try to execute _Py_TryXGetStackRef() on a stale cache entry value. If that value has been deallocated, PyStackRef_XCLOSE() will crash. This could happen before because the version was written first and then new value second. The fix is simply to write the entry value first and the version after. That way, the reader always sees a value at least as new as the version. Possible scenarios for the reader of the cache entry, as it is being written to concurrently: entry version entry value outcome old old Okay, type version will not match old new Okay, incref/decref works, seq check fails new old Bad, incref/decref on old value might crash new new Okay, incref/decref works, seq check fails Issue: gh-132942
Open Graph Description: Two races related to the type lookup cache, when used in the free-threaded build. This caused test_opcache to sometimes fail (as well as other hard to reproduce failures). The first problem is tha...
X Description: Two races related to the type lookup cache, when used in the free-threaded build. This caused test_opcache to sometimes fail (as well as other hard to reproduce failures). The first problem is tha...
Opengraph URL: https://github.com/python/cpython/pull/133032
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e93e6eae-0eed-acef-9111-989dca2044c3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ADE2:1F466:40C48C:578AC2:6A5801C7 |
| html-safe-nonce | 7ee670ae31015f54e23736d8486957bc137a09d1ac6e68cad5141c459c19b3ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREUyOjFGNDY2OjQwQzQ4Qzo1NzhBQzI6NkE1ODAxQzciLCJ2aXNpdG9yX2lkIjoiMTk2MzQ0OTU1Mzg5NTU1NTUyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6b84da00dd94f86d27a483e859171f3cea684537fa7ae661f1d1f0108abc2838 |
| hovercard-subject-tag | pull_request:2483735062 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/133032/files |
| twitter:image | https://avatars.githubusercontent.com/u/690853?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/690853?s=400&v=4 |
| og:image:alt | Two races related to the type lookup cache, when used in the free-threaded build. This caused test_opcache to sometimes fail (as well as other hard to reproduce failures). The first problem is tha... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 49c8c15fabcbf356d607a90ca115c13b273e42ff8b74155de050fd229a9b0121 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3fb1f684e7a833eb1b2d01d39875a2b52cb4fe9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width