Skip to content

Conversation

@nascheme
Copy link
Member

@nascheme nascheme commented Jan 19, 2026

When shutting down, disable deferred refcounting for all GC objects. It is important to do this also for untracked objects, which before this change were getting missed.

When shutting down, disable deferred refcounting for all GC objects. It
is important to do this also for untracked objects, which before this
change were getting missed.
We can remove the shutdown case disable_deferred_refcounting() call
inside scan_heap_visitor() if we are careful about it.  The key is
that frame_disable_deferred_refcounting() might fail if the object
is untracked.
@nascheme nascheme marked this pull request as ready for review January 20, 2026 06:24
@nascheme
Copy link
Member Author

@colesbury I think this is a correct fix but some of the details are a bit tricky. It seems the !_Py_IsImmortal(op) test is required before calling disable_deferred_refcounting() but I'm not 100% sure why. I'd expect that immortal objects should not also have deferred ref counting enabled for them. The need to check for _PyObject_GC_IS_TRACKED() before calling frame_disable_deferred_refcounting() makes sense.

I split the "disable deferred" into a separate heap scan. Doing it inside scan_heap_visitor() would add extra branches to the hot executate path. So, I think a separate scan and keeping scan_heap_visitor() faster is better.

@nascheme nascheme added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Jan 20, 2026
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @nascheme for commit 296eba9 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F144055%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Jan 20, 2026
@encukou
Copy link
Member

encukou commented Jan 20, 2026

The refleak test failure in test_capi (test_replaced_interpreter) is unrelated (#142913)

@encukou
Copy link
Member

encukou commented Jan 20, 2026

Otherwise, buildbots are happy.
I'll merge to help fix the tier-1 failures. Any follow-ups can go in separate PRs.

@encukou encukou merged commit 795d5c5 into python:main Jan 20, 2026
51 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news topic-free-threading type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants