René's URL Explorer Experiment


Title: GC in free-threaded build has problems with `Py_INCREF()`/`Py_DECREF()` in `tp_traverse` handlers · Issue #123241 · python/cpython · GitHub

Open Graph Title: GC in free-threaded build has problems with `Py_INCREF()`/`Py_DECREF()` in `tp_traverse` handlers · Issue #123241 · python/cpython

X Title: GC in free-threaded build has problems with `Py_INCREF()`/`Py_DECREF()` in `tp_traverse` handlers · Issue #123241 · python/cpython

Description: Bug report This came up in the context of nanobind. Nanobind implements (in a test) a traverse function: int funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) { FuncWrapper *w = nb::inst_ptr(self); nb::obje...

Open Graph Description: Bug report This came up in the context of nanobind. Nanobind implements (in a test) a traverse function: int funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) { FuncWrapper *w = n...

X Description: Bug report This came up in the context of nanobind. Nanobind implements (in a test) a traverse function: int funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) { FuncWrapper *w = n...

Opengraph URL: https://github.com/python/cpython/issues/123241

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"GC in free-threaded build has problems with `Py_INCREF()`/`Py_DECREF()` in `tp_traverse` handlers","articleBody":"# Bug report\n\nThis came up in the context of [nanobind](https://github.com/wjakob/nanobind/). Nanobind implements (in a test) a traverse function:\n\n```c++\nint funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) {\n    FuncWrapper *w = nb::inst_ptr\u003cFuncWrapper\u003e(self);\n\n    nb::object f = nb::cast(w-\u003ef, nb::rv_policy::none);\n    Py_VISIT(f.ptr());\n\n    return 0;\n};\n```\n\nThe ``nb::object`` smart pointer is internally reference counted. In other words, the above is roughly equivalent to:\n\n```c\nint funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) {\n    PyObject *f = self-\u003ew-\u003ef;\n    Py_INCREF(f);\n    Py_VISIT(f);\n    Py_DECREF(f);\n    return 0;\n};\n```\n\nThis leads to a leak in the free-threaded GC for subtle reasons: when determining resurrected objects, the free-threaded GC uses `ob_ref_local` to compute the refcount - incoming references, which may be (temporarily) negative. In this case, `Py_INCREF()` adds 1 to the refcount, but by the time `Py_DECREF()` is called, the local refcount is `-1` which makes the object appear immortal.\n\nThere are a number of limitations on the implementations of traverse functions, which are not well documented. For example, it's not safe to allocate, free, track, or untrack Python objects. It's unclear to me whether there are other issues with calling refcounting functions in traverse callbacks.\n\nI think we can make [`handle_resurrected_objects`](https://github.com/python/cpython/blob/297f2e093ec95800ae2184330b8408c875523467/Python/gc_free_threading.c#L974) more robust to this by splitting the first pass over `state-\u003eunreachable` into two passes.\n\nSee also: https://github.com/PyO3/pyo3/issues/3165, which was not related to the free-threaded build.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-142232\n* gh-142271\n* gh-142272\n* gh-142422\n* gh-142423\n* gh-142567\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2024-08-22T19:28:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/123241/cpython/issues/123241"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:495f42a6-5f8c-20ab-4deb-19430f575d06
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE3BE:1587BA:825556C:AC5FB44:696DEF75
html-safe-nonceb0106a19d30d203b25010967aa347e392cb5f68ff6fca21ae39b88a28426650e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0JFOjE1ODdCQTo4MjU1NTZDOkFDNUZCNDQ6Njk2REVGNzUiLCJ2aXNpdG9yX2lkIjoiNDY5Mzc2NjkyNDE4MTEzMzk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac4388d9ebce3f65c1211777f3e0ffb034d27114e641563121d3f97993c9cc7ac0
hovercard-subject-tagissue:2481556211
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/123241/issue_layout
twitter:imagehttps://opengraph.githubassets.com/03dc4f701d8e3097693eae206a96ab3ee4772a35bab6ab10d5aee4bcb8b0bde0/python/cpython/issues/123241
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/03dc4f701d8e3097693eae206a96ab3ee4772a35bab6ab10d5aee4bcb8b0bde0/python/cpython/issues/123241
og:image:altBug report This came up in the context of nanobind. Nanobind implements (in a test) a traverse function: int funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) { FuncWrapper *w = n...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecolesbury
hostnamegithub.com
expected-hostnamegithub.com
None4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7e5ae23c70136152637ceee8d6faceb35596ec46
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/123241#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F123241
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
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
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
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/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%2Fissues%2F123241
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%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/123241
Reloadhttps://github.com/python/cpython/issues/123241
Reloadhttps://github.com/python/cpython/issues/123241
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/123241
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k 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.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/123241
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 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/123241
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/123241
GC in free-threaded build has problems with Py_INCREF()/Py_DECREF() in tp_traverse handlershttps://github.com/python/cpython/issues/123241#top
https://github.com/pablogsal
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/colesbury
https://github.com/colesbury
colesburyhttps://github.com/colesbury
on Aug 22, 2024https://github.com/python/cpython/issues/123241#issue-2481556211
nanobindhttps://github.com/wjakob/nanobind/
handle_resurrected_objectshttps://github.com/python/cpython/blob/297f2e093ec95800ae2184330b8408c875523467/Python/gc_free_threading.c#L974
PyO3/pyo3#3165https://github.com/PyO3/pyo3/issues/3165
gh-123241: Don't modify ref count during visitation #142232https://github.com/python/cpython/pull/142232
gh-123241: Make gc_free_threading.c more robust to increfs/decrefs in tp_traverse #142271https://github.com/python/cpython/pull/142271
gh-123241: Document restrictions for tp_traverse implementations #142272https://github.com/python/cpython/pull/142272
[3.13] gh-123241: Document restrictions for tp_traverse implementations (gh-142272) #142422https://github.com/python/cpython/pull/142422
[3.14] gh-123241: Document restrictions for tp_traverse implementations (gh-142272) #142423https://github.com/python/cpython/pull/142423
[3.14] gh-123241: Don't modify ref count during visitation (GH-142232) #142567https://github.com/python/cpython/pull/142567
pablogsalhttps://github.com/pablogsal
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
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.