GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-153176: Fix destroy_interpreter() test helper clearing a non-current thread state by zangjiucheng · Pull Request #153307 · python/cpython

Conversation

@zangjiucheng

@zangjiucheng zangjiucheng commented Jul 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: Assertion triggered in MiMalloc (free-threaded build) #153176

Summary

Fixes #153176.

On free-threaded debug builds, _testinternalcapi.destroy_interpreter(id, basic=True)
aborted the process with:

Assertion `tstate == (_PyThreadStateImpl *)_PyThreadState_GET()' failed.

The root cause is in the test helper, not in obmalloc. destroy_interpreter()
calls PyThreadState_Clear(t1) / PyThreadState_Delete(t1) while t2 is the
current thread state. Clearing a non-current thread state runs
_PyThreadState_ClearMimallocHeaps(t1), and on a debug build
mi_heap_collect_ex() treats MI_ABANDON as >= MI_FORCE, so it calls
_mi_abandoned_reclaim_all() and reclaims abandoned pages back into t1's
heaps. That reaches _PyMem_mi_page_reclaimed(), where the reclaimed page
belongs to t1 but the current thread state is t2, so the assertion fires.

The assertion is correct — reclaim should only happen into the current thread's
own heap — so this keeps it and fixes the helper instead: t1 is left for
Py_EndInterpreter() to clean up, matching the rule that PyThreadState_Clear()
must be called on the current thread. Thanks @kumaraditya303 for pinpointing the
root cause.

Test plan

  • ./python -m test test_free_threading.test_interpreters -v
  • With the assertion in place, reproduced the abort on a free-threaded
    debug build before the fix; confirmed it no longer reproduces after.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zangjiucheng
Add tests and fix crash on free-threaded debug builds when destroying…
ba8f2ec
… subinterpreters
@bedevere-app bedevere-app Bot mentioned this pull request Jul 8, 2026
Assertion triggered in MiMalloc (free-threaded build) #153176
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Jul 8, 2026
@aisk
aisk requested a review from colesbury July 8, 2026 04:31
@weixlu

weixlu commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

I also think we can just relax this assertion. Thanks for your fix!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Jul 10, 2026
View reviewed changes
Comment thread Objects/obmalloc.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@zangjiucheng @kumaraditya303 @weixlu
pythongh-153176: Fix destroy_interpreter() helper clearing a non-curr…
5228662
…ent thread state

_testinternalcapi.destroy_interpreter(basic=True) called PyThreadState_Clear()
and PyThreadState_Delete() on t1 while t2 was the current thread state. On a
free-threaded debug build this reclaimed mimalloc pages into a heap not owned
by the current thread, tripping the assertion in _PyMem_mi_page_reclaimed().

Leave t1 for Py_EndInterpreter() to clean up. Add a regression test.

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Xiaowei Lu <[email protected]>
@kumaraditya303

kumaraditya303 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The PR title and description needs to be updated.

zangjiucheng reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Jul 23, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Tests/2026-07-22-00-00-00.gh-issue-153176.mZ8nQ4.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303 kumaraditya303 added the skip news label Jul 23, 2026
@zangjiucheng
Remove news entry not needed
80b86be
@zangjiucheng zangjiucheng changed the title gh-153176: Fix crash in _PyMem_mi_page_reclaimed on free-threaded debug builds gh-153176: Fix destroy_interpreter() test helper clearing a non-current thread state Jul 23, 2026
@zangjiucheng
zangjiucheng requested a review from kumaraditya303 July 23, 2026 14:22
kumaraditya303
kumaraditya303 approved these changes Jul 24, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jul 24, 2026
@kumaraditya303
kumaraditya303 merged commit 6e98393 into python:main Jul 24, 2026
113 of 115 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 24, 2026
@bedevere-bot

bedevere-bot commented Jul 24, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Stable LTO + PGO 3.x (tier-3) has failed when building commit 6e98393.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1627/builds/3097) and take a look at the build logs.
  4. Check if the failure is related to this commit (6e98393) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1627/builds/3097

Summary of the results of the build (if available):

Click to see traceback logs
Note: switching to '6e983938834a8b6c7043369b3c5de2b5d2084ea4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 6e983938834a8 gh-153176: Fix destroy_interpreter() test helper clearing a non-current thread state (#153307)
Switched to and reset branch 'main'

find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
make[2]: [Makefile:3474: clean-retain-profile] Error 1 (ignored)
./Modules/socketmodule.c: In function ‘getsockaddrarg’:
./Modules/socketmodule.c:2646:9: warning: ‘strncpy’ specified bound 64 equals destination size [-Wstringop-truncation]
 2646 |         strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld.bfd: final link failed: No space left on device
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:1891: Programs/_freeze_module] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile:996: profile-gen-stamp] Error 2
make: *** [Makefile:1008: profile-run-stamp] Error 2
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Jul 24, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Stable LTO 3.x (tier-3) has failed when building commit 6e98393.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1654/builds/3074) and take a look at the build logs.
  4. Check if the failure is related to this commit (6e98393) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1654/builds/3074

Summary of the results of the build (if available):

Click to see traceback logs
Note: switching to '6e983938834a8b6c7043369b3c5de2b5d2084ea4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 6e983938834a8 gh-153176: Fix destroy_interpreter() test helper clearing a non-current thread state (#153307)
Switched to and reset branch 'main'

Assembler messages:
Fatal error: can't create Modules/resource.o: No space left on device
Assembler messages:
Fatal error: can't create Modules/_multiprocessing/posixshmem.o: No space left on device
make: *** [Makefile:3781: Modules/resource.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [Makefile:3791: Modules/_multiprocessing/posixshmem.o] Error 1
/tmp/ccTKtqke.s: Assembler messages:
/tmp/ccTKtqke.s: Fatal error: can't write 332 bytes to section .text of Modules/expat/xmlparse.o: 'No space left on device'
Assembler messages:
Fatal error: can't create Modules/termios.o: No space left on device
make: *** [Makefile:3789: Modules/termios.o] Error 1
/tmp/cc8EHqEG.s: Assembler messages:
Fatal error: can't create Modules/syslogmodule.o: No space left on device
Assembler messages:
/tmp/cc8EHqEG.s: Fatal error: can't write 3951 bytes to section .gnu.lto_packed_name_dawg.83.a1122b6197080a2a of Modules/unicodedata.o: 'No space left on device'
make: *** [Makefile:3787: Modules/syslogmodule.o] Error 1
/tmp/ccTKtqke.s: Fatal error: Modules/expat/xmlparse.o: No such file or directory
make: *** [Makefile:1614: Modules/expat/xmlparse.o] Error 1
/tmp/cc8EHqEG.s: Fatal error: Modules/unicodedata.o: No such file or directory
make: *** [Makefile:3771: Modules/unicodedata.o] Error 1
/tmp/ccYg48Cu.s: Assembler messages:
/tmp/ccYg48Cu.s: Fatal error: can't write 3952 bytes to section .gnu.debuglto_.debug_info of Modules/selectmodule.o: 'No space left on device'
/tmp/ccvInZys.s: Assembler messages:
/tmp/ccvInZys.s: Fatal error: Modules/mmapmodule.o: No space left on device
make: *** [Makefile:3777: Modules/mmapmodule.o] Error 1
make: *** [Makefile:3783: Modules/selectmodule.o] Error 1
/tmp/cc8yXini.s: Assembler messages:
/tmp/cc8yXini.s: Fatal error: can't write 3951 bytes to section .gnu.lto_.decls.eddbfbeabee625fb of Modules/socketmodule.o: 'No space left on device'
/tmp/cc8yXini.s: Fatal error: Modules/socketmodule.o: No such file or directory
make: *** [Makefile:3785: Modules/socketmodule.o] Error 1

find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
make: [Makefile:3474: clean-retain-profile] Error 1 (ignored)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
@zangjiucheng @kumaraditya303
@weixlu @mbeijen
pythongh-153176: Fix destroy_interpreter() test helper clearing a non…
baf1c4d
…-current thread state (python#153307)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Xiaowei Lu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@colesbury colesbury Awaiting requested review from colesbury

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Assertion triggered in MiMalloc (free-threaded build)

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@zangjiucheng @weixlu @kumaraditya303 @bedevere-bot @colesbury
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.