Skip to content

Python 3.14.0a5 i686 Linux freethreading-debug build fails: gc_free_threading.c:1077: mark_heap_visitor: Assertion "gc_get_refs(op) >= 0" failed: refcount is too small #130030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
befeleme opened this issue Feb 12, 2025 · 2 comments
Labels
3.14 bugs and security fixes build The build process and cross-build topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@befeleme
Copy link
Contributor

befeleme commented Feb 12, 2025

Bug report

Bug description:

I try to build freethreading-debug Python 3.14.0a5 for i686 Fedora Linux with a consistent failure: /builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Python/gc_free_threading.c:1077: mark_heap_visitor: Assertion "gc_get_refs(op) >= 0" failed: refcount is too small. This happens when freezing importlib._bootstrap_external, zipimport, importlib._bootstrap.
The bigger log excerpt:

./Programs/_freeze_module getpath /builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Modules/getpath.py Python/frozen_modules/getpath.h
./Programs/_freeze_module importlib._bootstrap_external /builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Lib/importlib/_bootstrap_external.py Python/frozen_modules/importlib._bootstrap_external.h
/builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Python/gc_free_threading.c:1077: mark_heap_visitor: Assertion "gc_get_refs(op) >= 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback
object address  : 0xefc48188
object refcount : 1
object type     : 0x56bef880
object type name: staticmethod
object repr     : <staticmethod(<built-in method maketrans of type object at 0x56be6ac0>)>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: core initialized
Stack (most recent call first):
  <no Python frame>
make: *** [Makefile:1772: Python/frozen_modules/importlib._bootstrap_external.h] Aborted (core dumped)
make: *** Waiting for unfinished jobs....
./Programs/_freeze_module zipimport /builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Lib/zipimport.py Python/frozen_modules/zipimport.h
/builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Python/gc_free_threading.c:1077: mark_heap_visitor: Assertion "gc_get_refs(op) >= 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback
object address  : 0xefc48188
object refcount : 1
object type     : 0x56be0880
object type name: staticmethod
object repr     : <staticmethod(<built-in method maketrans of type object at 0x56bd7ac0>)>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: core initialized
Stack (most recent call first):
  <no Python frame>
make: *** [Makefile:1775: Python/frozen_modules/zipimport.h] Aborted (core dumped)
./Programs/_freeze_module importlib._bootstrap /builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Lib/importlib/_bootstrap.py Python/frozen_modules/importlib._bootstrap.h
/builddir/build/BUILD/python3.14-3.14.0_a5-build/Python-3.14.0a5/Python/gc_free_threading.c:1077: mark_heap_visitor: Assertion "gc_get_refs(op) >= 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback
object address  : 0xefc48188
object refcount : 1
object type     : 0x56bb7880
object type name: staticmethod
object repr     : <staticmethod(<built-in method maketrans of type object at 0x56baeac0>)>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: core initialized
Stack (most recent call first):
  <no Python frame>
make: *** [Makefile:1769: Python/frozen_modules/importlib._bootstrap.h] Aborted (core dumped)

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

@befeleme befeleme added the type-bug An unexpected behavior, bug, or error label Feb 12, 2025
@hugovk hugovk added topic-free-threading 3.14 bugs and security fixes labels Feb 12, 2025
@picnixz picnixz added the build The build process and cross-build label Feb 12, 2025
@colesbury
Copy link
Contributor

Thanks, I'm able to repro this and should have a fix soon.

colesbury added a commit to colesbury/cpython that referenced this issue Feb 12, 2025
The `gc_get_refs` assertion needs to be after we check the alive and
unreachable bits. Otherwise, `ob_tid` may store the actual thread id
instead of the computed `gc_refs`, which may trigger the assertion if
the `ob_tid` looks like a negative value.

Also fix a few type warnings on 32-bit systems.
colesbury added a commit that referenced this issue Feb 12, 2025
The `gc_get_refs` assertion needs to be after we check the alive and
unreachable bits. Otherwise, `ob_tid` may store the actual thread id
instead of the computed `gc_refs`, which may trigger the assertion if
the `ob_tid` looks like a negative value.

Also fix a few type warnings on 32-bit systems.
@befeleme
Copy link
Contributor Author

Thank you, the fix indeed solves the issue in my build.

befeleme pushed a commit to fedora-python/cpython that referenced this issue Mar 17, 2025
…pythongh-130043)

The `gc_get_refs` assertion needs to be after we check the alive and
unreachable bits. Otherwise, `ob_tid` may store the actual thread id
instead of the computed `gc_refs`, which may trigger the assertion if
the `ob_tid` looks like a negative value.

Also fix a few type warnings on 32-bit systems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes build The build process and cross-build topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants