René's URL Explorer Experiment


Title: gh-148820: Fix `_PyRawMutex` use-after-free on spurious semaphore wakeup by colesbury · Pull Request #148847 · python/cpython · GitHub

Open Graph Title: gh-148820: Fix `_PyRawMutex` use-after-free on spurious semaphore wakeup by colesbury · Pull Request #148847 · python/cpython

X Title: gh-148820: Fix `_PyRawMutex` use-after-free on spurious semaphore wakeup by colesbury · Pull Request #148847 · python/cpython

Description: _PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then calls _PySemaphore_Wakeup, with no handshake (unlike parking_lot's wait_entry.is_unparking protocol). If the waiter's _PySemaphore_Wait returns for any reason other than the matching Wakeup — e.g. Py_PARK_INTR from sigint_event on the main thread on Windows, or EINTR on POSIX — the waiter can exit the wait, re-acquire the mutex (already CAS-unlocked by the unlocker), break out of the loop, and call _PySemaphore_Destroy on the stack-allocated semaphore before the unlocker's _PySemaphore_Wakeup runs. That Wakeup then hits a closed handle, producing Fatal Python error: _PySemaphore_Wakeup: parking_lot: ReleaseSemaphore failed (Win32 ERROR_INVALID_HANDLE). Observed on free-threaded 3.14 on Windows with coverage run + trio + signal.raise_signal(SIGINT) from a non-main thread. Parking-lot's _PyParkingLot_Park is not affected because its bucket-locked is_unparking handshake already ensures the parker waits for the unparker's Wakeup before destroying the semaphore. Fix Loop in _PyRawMutex_LockSlow until _PySemaphore_Wait returns Py_PARK_OK. Py_PARK_OK is only returned when a matching post was observed on all backends (WAIT_OBJECT_0 / sem_wait success / sema->counter > 0), so looping until OK guarantees the unlocker's pending Wakeup has fired before we destroy the semaphore. Deferring SIGINT until the unlock completes is acceptable in practice: _PyRawMutex protects only short critical sections (principally parking-lot bucket locks), so ctrl-C is delivered near-immediately. Also include GetLastError() and the HANDLE value in the Windows fatal messages in _PySemaphore_Init, _PySemaphore_Wait, and _PySemaphore_Wakeup — these were key in identifying the bug as a use-after-free (error 6 = ERROR_INVALID_HANDLE) rather than a double-release. The _PySemaphore_Wakeup API signature is intentionally left unchanged to preserve the ability to backport this fix. Based on analysis and patch by @colesbury in https://gist.github.com/colesbury/3e4c6180e3eb4b3b9fd07b26f3196e12 / https://gist.github.com/colesbury/f9f0c5cf1a00f2c946e80795fcc245d7. Verification Stress harness (16 workers × 100 iterations × coverage run of the trio SIGINT-from-thread reproducer) showed ~0.19% crash rate on the unpatched baseline and 0% with the loop. Issue: gh-148820

Open Graph Description: _PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then calls _PySemaphore_Wakeup, with no handshake (unlike parking_lot's wait_entry.is_unparking protocol). If the waiter's _P...

X Description: _PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then calls _PySemaphore_Wakeup, with no handshake (unlike parking_lot's wait_entry.is_unparking protocol). If the waiter&...

Opengraph URL: https://github.com/python/cpython/pull/148847

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:ebee146b-2376-6f6b-f5f0-acb36f7df0a0
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC84E:8AF77:24E86A:324B0C:6A57FA88
html-safe-noncee7fd871187b69a5cdb39441aeedf56c9100ae82e0486b7a5b908e93bfdd8f99f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODRFOjhBRjc3OjI0RTg2QTozMjRCMEM6NkE1N0ZBODgiLCJ2aXNpdG9yX2lkIjoiNTAyODc4OTQzNjk5NTMzNjg0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacad5e6085ad9bef95db3b317f0ff9fc7951caad5fdb4ed4ac751b8093fc7ed0c5
hovercard-subject-tagpull_request:3563481419
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/148847/files
twitter:imagehttps://avatars.githubusercontent.com/u/655866?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/655866?s=400&v=4
og:image:alt_PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then calls _PySemaphore_Wakeup, with no handshake (unlike parking_lot's wait_entry.is_unparking protocol). If the waiter's _P...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None49c8c15fabcbf356d607a90ca115c13b273e42ff8b74155de050fd229a9b0121
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release3fb1f684e7a833eb1b2d01d39875a2b52cb4fe9b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/148847/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F148847%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F148847%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/148847/files
Reloadhttps://github.com/python/cpython/pull/148847/files
Reloadhttps://github.com/python/cpython/pull/148847/files
Please reload this pagehttps://github.com/python/cpython/pull/148847/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/148847/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
colesburyhttps://github.com/colesbury
python:mainhttps://github.com/python/cpython/tree/main
colesbury:gh-148820-raw-mutex-park-intrhttps://github.com/colesbury/cpython/tree/gh-148820-raw-mutex-park-intr
Conversation 0 https://github.com/python/cpython/pull/148847
Commits 1 https://github.com/python/cpython/pull/148847/commits
Checks 50 https://github.com/python/cpython/pull/148847/checks
Files changed https://github.com/python/cpython/pull/148847/files
Please reload this pagehttps://github.com/python/cpython/pull/148847/files
gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup https://github.com/python/cpython/pull/148847/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/148847/files
52bf353 gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup colesbury Apr 21, 2026 https://github.com/python/cpython/pull/148847/commits/52bf353d1d907d3d0c0e7bf4064dfab852c04d26
Clear filters https://github.com/python/cpython/pull/148847/files
Please reload this pagehttps://github.com/python/cpython/pull/148847/files
Please reload this pagehttps://github.com/python/cpython/pull/148847/files
2026-04-21-14-36-44.gh-issue-148820.XhOGhA.rst https://github.com/python/cpython/pull/148847/files#diff-2aaa69ac5830e1f4c93b20163236dd08910272eb3e18c96a2cdcbdf34cce4fab
lock.c https://github.com/python/cpython/pull/148847/files#diff-8a628e2db62193e1be26995ded4a1da56d11a156b4e9190984c910f1b019a962
parking_lot.c https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
Misc/NEWS.d/next/Core_and_Builtins/2026-04-21-14-36-44.gh-issue-148820.XhOGhA.rsthttps://github.com/python/cpython/pull/148847/files#diff-2aaa69ac5830e1f4c93b20163236dd08910272eb3e18c96a2cdcbdf34cce4fab
View file https://github.com/colesbury/cpython/blob/52bf353d1d907d3d0c0e7bf4064dfab852c04d26/Misc/NEWS.d/next/Core_and_Builtins/2026-04-21-14-36-44.gh-issue-148820.XhOGhA.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/148847/{{ revealButtonHref }}
Python/lock.chttps://github.com/python/cpython/pull/148847/files#diff-8a628e2db62193e1be26995ded4a1da56d11a156b4e9190984c910f1b019a962
View file https://github.com/colesbury/cpython/blob/52bf353d1d907d3d0c0e7bf4064dfab852c04d26/Python/lock.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/148847/{{ revealButtonHref }}
https://github.com/python/cpython/pull/148847/files#diff-8a628e2db62193e1be26995ded4a1da56d11a156b4e9190984c910f1b019a962
https://github.com/python/cpython/pull/148847/files#diff-8a628e2db62193e1be26995ded4a1da56d11a156b4e9190984c910f1b019a962
Python/parking_lot.chttps://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
View file https://github.com/colesbury/cpython/blob/52bf353d1d907d3d0c0e7bf4064dfab852c04d26/Python/parking_lot.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/148847/{{ revealButtonHref }}
https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
https://github.com/python/cpython/pull/148847/files#diff-07311442b92831545c9c6e7864f4c0e9c0826d78e84d9ff522e2914865dc0b19
Please reload this pagehttps://github.com/python/cpython/pull/148847/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.