Skip to content

Crash due to broken refcounting #51

@mgorny

Description

@mgorny

When Python is built with assertions enabled (--with-assertions or --with-pydebug), the package crashes while testing, for example:

$ git rev-parse HEAD
9a0b57fd5429175a783d9e8af3bc07aa91cc6c13
$ uv venv -p 3.14
Using CPython 3.14.5 interpreter at: /usr/bin/python3.14
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
$ uv pip install -e . pytest pytest-asyncio
Resolved 7 packages in 268ms
      Built cachebox @ file:///tmp/cachebox
Prepared 1 package in 33.12s
░░░░░░░░░░░░░░░░░░░░ [0/7] Installing wheels...                                                                                        warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
         If the cache and target directories are on different filesystems, hardlinking may not be supported.
         If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.
Installed 7 packages in 17ms
 + cachebox==5.2.3 (from file:///tmp/cachebox)
 + iniconfig==2.3.0
 + packaging==26.2
 + pluggy==1.6.0
 + pygments==2.20.0
 + pytest==9.0.3
 + pytest-asyncio==1.3.0
$ .venv/bin/pytest -vs
========================================================= test session starts =========================================================
platform linux -- Python 3.14.5, pytest-9.0.3, pluggy-1.6.0 -- /tmp/cachebox/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /tmp/cachebox
configfile: pyproject.toml
plugins: asyncio-1.3.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 272 items                                                                                                                   

python/tests/test_caches.py::TestCache::test__new__ PASSED
python/tests/test_caches.py::TestCache::test_overflow PASSED
python/tests/test_caches.py::TestCache::test_maxmemory_config PASSED
python/tests/test_caches.py::TestCache::test_maxmemory_enforced PASSED
python/tests/test_caches.py::TestCache::test_maxmemory_enforced_base_types PASSED
python/tests/test_caches.py::TestCache::test_update_overflow_preserves_entry PASSED
python/tests/test_caches.py::TestCache::test_update_sizeof_error_preserves_entry PASSED
python/tests/test_caches.py::TestCache::test___len__ PASSED
python/tests/test_caches.py::TestCache::test___contains__ PASSED
python/tests/test_caches.py::TestCache::test___setitem__ PASSED
python/tests/test_caches.py::TestCache::test___repr__ PASSED
python/tests/test_caches.py::TestCache::test_insert PASSED
python/tests/test_caches.py::TestCache::test_get PASSED
python/tests/test_caches.py::TestCache::test_pop PASSED
python/tests/test_caches.py::TestCache::test_setdefault PASSED
python/tests/test_caches.py::TestCache::test_clear PASSED
python/tests/test_caches.py::TestCache::test_update PASSED
python/tests/test_caches.py::TestCache::test_eq_implemetation PASSED
python/tests/test_caches.py::TestCache::test_iterators PASSED
python/tests/test_caches.py::TestCache::test___eq__ PASSED
python/tests/test_caches.py::TestCache::test_copy PASSED
python/tests/test_caches.py::TestCache::test_cache_type PASSED
python/tests/test_caches.py::TestCache::test_pickle PASSED
python/tests/test_caches.py::TestFIFOCache::test__new__ PASSED
python/tests/test_caches.py::TestFIFOCache::test_overflow PASSED
python/tests/test_caches.py::TestFIFOCache::test_maxmemory_config PASSED
python/tests/test_caches.py::TestFIFOCache::test_maxmemory_enforced PASSED
python/tests/test_caches.py::TestFIFOCache::test_maxmemory_enforced_base_types PASSED
python/tests/test_caches.py::TestFIFOCache::test_update_overflow_preserves_entry PASSED
python/tests/test_caches.py::TestFIFOCache::test_update_sizeof_error_preserves_entry PASSED
python/tests/test_caches.py::TestFIFOCache::test___len__ PASSED
python/tests/test_caches.py::TestFIFOCache::test___contains__ PASSED
python/tests/test_caches.py::TestFIFOCache::test___setitem__ PASSED
python/tests/test_caches.py::TestFIFOCache::test___repr__ PASSED
python/tests/test_caches.py::TestFIFOCache::test_insert PASSED
python/tests/test_caches.py::TestFIFOCache::test_get PASSED
python/tests/test_caches.py::TestFIFOCache::test_pop PASSED
python/tests/test_caches.py::TestFIFOCache::test_setdefault PASSED
python/tests/test_caches.py::TestFIFOCache::test_clear PASSED
python/tests/test_caches.py::TestFIFOCache::test_update PASSED
python/tests/test_caches.py::TestFIFOCache::test_eq_implemetation PASSED
python/tests/test_caches.py::TestFIFOCache::test_iterators PASSED
python/tests/test_caches.py::TestFIFOCache::test___eq__ PASSED
python/tests/test_caches.py::TestFIFOCache::test_copy PASSED
python/tests/test_caches.py::TestFIFOCache::test_cache_type PASSED
python/tests/test_caches.py::TestFIFOCache::test_policy PASSED
python/tests/test_caches.py::TestFIFOCache::test_update_can_evict_self_on_maxmemory PASSED
python/tests/test_caches.py::TestFIFOCache::test_ordered_iterators PASSED
python/tests/test_caches.py::TestFIFOCache::test_pickle PASSED
python/tests/test_caches.py::TestFIFOCache::test_first_last PASSED
python/tests/test_caches.py::TestRRCache::test__new__ PASSED
python/tests/test_caches.py::TestRRCache::test_overflow PASSED
python/tests/test_caches.py::TestRRCache::test_maxmemory_config PASSED
python/tests/test_caches.py::TestRRCache::test_maxmemory_enforced PASSED
python/tests/test_caches.py::TestRRCache::test_maxmemory_enforced_base_types PASSED
python/tests/test_caches.py::TestRRCache::test_update_overflow_preserves_entry PASSED
python/tests/test_caches.py::TestRRCache::test_update_sizeof_error_preserves_entry PASSED
python/tests/test_caches.py::TestRRCache::test___len__ PASSED
python/tests/test_caches.py::TestRRCache::test___contains__ PASSED
python/tests/test_caches.py::TestRRCache::test___setitem__ PASSED
python/tests/test_caches.py::TestRRCache::test___repr__ PASSED
python/tests/test_caches.py::TestRRCache::test_insert PASSED
python/tests/test_caches.py::TestRRCache::test_get PASSED
python/tests/test_caches.py::TestRRCache::test_pop PASSED
python/tests/test_caches.py::TestRRCache::test_setdefault PASSED
python/tests/test_caches.py::TestRRCache::test_clear PASSED
python/tests/test_caches.py::TestRRCache::test_update PASSED
python/tests/test_caches.py::TestRRCache::test_eq_implemetation PASSED
python/tests/test_caches.py::TestRRCache::test_iterators PASSED
python/tests/test_caches.py::TestRRCache::test___eq__ PASSED
python/tests/test_caches.py::TestRRCache::test_copy PASSED
python/tests/test_caches.py::TestRRCache::test_cache_type PASSED
python/tests/test_caches.py::TestRRCache::test_popitem PASSED
python/tests/test_caches.py::TestRRCache::test_pickle PASSED
python/tests/test_caches.py::TestLRUCache::test__new__ PASSED
python/tests/test_caches.py::TestLRUCache::test_overflow PASSED
python/tests/test_caches.py::TestLRUCache::test_maxmemory_config PASSED
python/tests/test_caches.py::TestLRUCache::test_maxmemory_enforced PASSED
python/tests/test_caches.py::TestLRUCache::test_maxmemory_enforced_base_types PASSED
python/tests/test_caches.py::TestLRUCache::test_update_overflow_preserves_entry PASSED
python/tests/test_caches.py::TestLRUCache::test_update_sizeof_error_preserves_entry PASSED
python/tests/test_caches.py::TestLRUCache::test___len__ PASSED
python/tests/test_caches.py::TestLRUCache::test___contains__ PASSED
python/tests/test_caches.py::TestLRUCache::test___setitem__ PASSED
python/tests/test_caches.py::TestLRUCache::test___repr__ PASSED
python/tests/test_caches.py::TestLRUCache::test_insert PASSED
python/tests/test_caches.py::TestLRUCache::test_get PASSED
python/tests/test_caches.py::TestLRUCache::test_pop PASSED
python/tests/test_caches.py::TestLRUCache::test_setdefault PASSED
python/tests/test_caches.py::TestLRUCache::test_clear PASSED
python/tests/test_caches.py::TestLRUCache::test_update PASSED
python/tests/test_caches.py::TestLRUCache::test_eq_implemetation PASSED
python/tests/test_caches.py::TestLRUCache::test_iterators PASSED
python/tests/test_caches.py::TestLRUCache::test___eq__ PASSED
python/tests/test_caches.py::TestLRUCache::test_copy PASSED
python/tests/test_caches.py::TestLRUCache::test_cache_type PASSED
python/tests/test_caches.py::TestLRUCache::test_policy PASSED
python/tests/test_caches.py::TestLRUCache::test_ordered_iterators PASSED
python/tests/test_caches.py::TestLRUCache::test_recently_used_funcs PASSED
python/tests/test_caches.py::TestLRUCache::test_pickle PASSED
python/tests/test_caches.py::TestLFUCache::test__new__ PASSED
python/tests/test_caches.py::TestLFUCache::test_overflow PASSED
python/tests/test_caches.py::TestLFUCache::test_maxmemory_config PASSED
python/tests/test_caches.py::TestLFUCache::test_maxmemory_enforced PASSED
python/tests/test_caches.py::TestLFUCache::test_maxmemory_enforced_base_types PASSED
python/tests/test_caches.py::TestLFUCache::test_update_overflow_preserves_entry PASSED
python/tests/test_caches.py::TestLFUCache::test_update_sizeof_error_preserves_entry PASSED
python/tests/test_caches.py::TestLFUCache::test___len__ PASSED
python/tests/test_caches.py::TestLFUCache::test___contains__ PASSED
python/tests/test_caches.py::TestLFUCache::test___setitem__ PASSED
python/tests/test_caches.py::TestLFUCache::test___repr__ PASSED
python/tests/test_caches.py::TestLFUCache::test_insert PASSED
python/tests/test_caches.py::TestLFUCache::test_get PASSED
python/tests/test_caches.py::TestLFUCache::test_pop PASSED
python/tests/test_caches.py::TestLFUCache::test_setdefault PASSED
python/tests/test_caches.py::TestLFUCache::test_clear PASSED
python/tests/test_caches.py::TestLFUCache::test_update PASSED
python/tests/test_caches.py::TestLFUCache::test_eq_implemetation Python/gc.c:94: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x7f5ae009d580
object refcount : 1
object type     : 0x7f5ae34661a0
object type name: dict
object repr     : {'nodeid': 'python/tests/test_caches.py::TestFIFOCache::test_copy', 'location': ('python/tests/mixin.py', 534, 'TestFIFOCache.test_copy'), 'keywords': {'test_copy': 1, 'TestFIFOCache': 1, 'test_caches.py': 1, 'tests': 1, 'python': 1, 'cachebox': 1, '': 1}, 'outcome': 'passed', 'longrepr': None, 'when': 'teardown', 'user_properties': [], 'sections': [], 'duration': 4.526599968812661e-05, 'start': 1778912673.7311203, 'stop': 1778912673.7311656}

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized

Current thread 0x00007f5ae35bdbc0 [pytest] (most recent call first):
  Garbage-collecting
  File "/tmp/cachebox/python/tests/mixin.py", line 23 in __init__
  File "/tmp/cachebox/python/tests/mixin.py", line 372 in test_eq_implemetation
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/python.py", line 166 in pytest_pyfunc_call
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/python.py", line 1720 in runtest
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 179 in pytest_runtest_call
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 245 in <lambda>
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 353 in from_call
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 244 in call_and_report
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 137 in runtestprotocol
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 118 in pytest_runtest_protocol
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/main.py", line 396 in pytest_runtestloop
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/main.py", line 372 in _main
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/main.py", line 318 in wrap_session
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/main.py", line 365 in pytest_cmdline_main
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/config/__init__.py", line 199 in main
  File "/tmp/cachebox/.venv/lib/python3.14/site-packages/_pytest/config/__init__.py", line 223 in console_main
  File "/tmp/cachebox/.venv/bin/pytest", line 10 in <module>
Aborted                    (core dumped) .venv/bin/pytest -vs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions