libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.58k stars 382 forks source link

Test suite semi-randomly crashes with python: Python/pystate.c:332: unbind_gilstate_tstate: `Assertion `tstate == gilstate_tss_get(tstate->interp->runtime)' failed.` #1234

Closed mgorny closed 9 months ago

mgorny commented 9 months ago

When CPython 3.12.0rc3 is built --with-assertions, pygit2's test suite crashes after running some tests; sometimes fewer, sometimes more.

$ python -m pytest
========================================================= test session starts =========================================================
platform linux -- Python 3.12.0rc3, pytest-7.4.2, pluggy-1.3.0 -- /tmp/pygit2/.venv/bin/python
cachedir: .pytest_cache
rootdir: /tmp/pygit2
configfile: pytest.ini
testpaths: test/
plugins: forked-1.6.0, cov-4.1.0
collected 479 items                                                                                                                   

test/test_apply_diff.py::test_apply_type_error PASSED
test/test_apply_diff.py::test_apply_diff_to_workdir PASSED
test/test_apply_diff.py::test_apply_diff_to_index PASSED
test/test_apply_diff.py::test_apply_diff_to_both PASSED
test/test_apply_diff.py::test_diff_applies_to_workdir PASSED
test/test_apply_diff.py::test_diff_applies_to_index PASSED
test/test_apply_diff.py::test_diff_applies_to_both PASSED
test/test_apply_diff.py::test_applies_error PASSED
test/test_archive.py::test_write_tree PASSED
test/test_archive.py::test_write_commit PASSED
test/test_attributes.py::test_no_attr PASSED
test/test_attributes.py::test_no_attr_aspath PASSED
test/test_blame.py::test_blame_index PASSED
test/test_blame.py::test_blame_flags PASSED
test/test_blame.py::test_blame_with_invalid_index PASSED
test/test_blame.py::test_blame_for_line PASSED
test/test_blame.py::test_blame_with_invalid_line PASSED
test/test_blame.py::test_blame_newest PASSED
test/test_blob.py::test_read_blob PASSED
test/test_blob.py::test_create_blob PASSED
test/test_blob.py::test_create_blob_fromworkdir PASSED
test/test_blob.py::test_create_blob_fromworkdir_aspath PASSED
test/test_blob.py::test_create_blob_outside_workdir PASSED
test/test_blob.py::test_create_blob_fromdisk PASSED
test/test_blob.py::test_create_blob_fromiobase PASSED
test/test_blob.py::test_diff_blob PASSED
test/test_blob.py::test_diff_blob_to_buffer PASSED
test/test_blob.py::test_diff_blob_to_buffer_patch_patch PASSED
test/test_blob.py::test_diff_blob_to_buffer_delete PASSED
test/test_blob.py::test_diff_blob_create PASSED
test/test_blob.py::test_blob_from_repo PASSED
test/test_branch.py::test_branches_getitem PASSED
test/test_branch.py::test_branches PASSED
test/test_branch.py::test_branches_create PASSED
test/test_branch.py::test_branches_delete PASSED
test/test_branch.py::test_branches_delete_error PASSED
test/test_branch.py::test_branches_is_head PASSED
test/test_branch.py::test_branches_is_not_head PASSED
test/test_branch.py::test_branches_rename PASSED
test/test_branch.py::test_branches_rename_error PASSED
test/test_branch.py::test_branches_rename_force PASSED
test/test_branch.py::test_branches_rename_invalid PASSED
test/test_branch.py::test_branches_name PASSED
test/test_branch.py::test_branches_with_commit PASSED
test/test_branch.py::test_lookup_branch_local PASSED
test/test_branch.py::test_listall_branches PASSED
test/test_branch.py::test_create_branch PASSED
test/test_branch.py::test_delete PASSED
test/test_branch.py::test_cant_delete_master PASSED
test/test_branch.py::test_branch_is_head_returns_true_if_branch_is_head PASSED
test/test_branch.py::test_branch_is_head_returns_false_if_branch_is_not_head PASSED
test/test_branch.py::test_branch_is_checked_out_returns_true_if_branch_is_checked_out PASSED
test/test_branch.py::test_branch_is_checked_out_returns_false_if_branch_is_not_checked_out PASSED
test/test_branch.py::test_branch_rename_succeeds PASSED
test/test_branch.py::test_branch_rename_fails_if_destination_already_exists PASSED
test/test_branch.py::test_branch_rename_not_fails_if_force_is_true PASSED
test/test_branch.py::test_branch_rename_fails_with_invalid_names PASSED
test/test_branch.py::test_branch_name PASSED
test/test_branch_empty.py::test_branches_remote_get PASSED
test/test_branch_empty.py::test_branches_remote PASSED
test/test_branch_empty.py::test_branches_remote_getitem PASSED
test/test_branch_empty.py::test_branches_upstream python: Python/pystate.c:332: unbind_gilstate_tstate: Assertion `tstate == gilstate_tss_get(tstate->interp->runtime)' failed.
Fatal Python error: Aborted

Current thread 0x00007f565e8d56c0 (most recent call first):
  <no Python frame>

Thread 0x00007f566472b740 (most recent call first):
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pygit2/remote.py", line 139 in fetch
  File "/tmp/pygit2/test/test_branch_empty.py", line 36 in repo
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 895 in call_fixture_func
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 1123 in pytest_fixture_setup
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 1069 in execute
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 693 in _compute_fixture_value
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 607 in _get_active_fixturedef
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 585 in getfixturevalue
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 566 in _fillfixtures
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/python.py", line 1795 in setup
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 494 in setup
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 157 in pytest_runtest_setup
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 262 in <lambda>
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 341 in from_call
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 261 in call_runtest_hook
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 222 in call_and_report
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 127 in runtestprotocol
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 114 in pytest_runtest_protocol
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/main.py", line 350 in pytest_runtestloop
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/main.py", line 325 in _main
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/main.py", line 271 in wrap_session
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/main.py", line 318 in pytest_cmdline_main
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 169 in main
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 192 in console_main
  File "/tmp/pygit2/.venv/lib/python3.12/site-packages/pytest/__main__.py", line 5 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

Extension modules: pygit2._pygit2, _cffi_backend (total: 2)
Aborted (core dumped)

Backtrace:

Core was generated by `python -m pytest'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44  pthread_kill.c: No such file or directory.
[Current thread is 1 (Thread 0x7f565e8d56c0 (LWP 130342))]
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007f5663ca2e2f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007f5663c52cc2 in __GI_raise (sig=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f566422e776 in faulthandler_fatal_error (signum=6) at ./Modules/faulthandler.c:330
#4  <signal handler called>
#5  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#6  0x00007f5663ca2e2f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#7  0x00007f5663c52cc2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#8  0x00007f5663c3b4ed in __GI_abort () at abort.c:79
#9  0x00007f5663c3b415 in __assert_fail_base (fmt=0x7f5663db8b98 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x7f566436ffe0 "tstate == gilstate_tss_get(tstate->interp->runtime)", 
    file=file@entry=0x7f566436fd3d "Python/pystate.c", line=line@entry=332, 
    function=function@entry=0x7f5664371040 <__PRETTY_FUNCTION__.66> "unbind_gilstate_tstate") at assert.c:92
#10 0x00007f5663c4b5e2 in __assert_fail (assertion=0x7f566436ffe0 "tstate == gilstate_tss_get(tstate->interp->runtime)", 
    file=0x7f566436fd3d "Python/pystate.c", line=332, function=0x7f5664371040 <__PRETTY_FUNCTION__.66> "unbind_gilstate_tstate")
    at assert.c:101
#11 0x00007f56641e3211 in unbind_gilstate_tstate (tstate=0x7f56580037d0) at Python/pystate.c:332
#12 0x00007f56641e6fab in tstate_delete_common (tstate=0x7f56580037d0) at Python/pystate.c:1540
#13 0x00007f56641e70bd in PyThreadState_Delete (tstate=0x7f56580037d0) at Python/pystate.c:1569
#14 0x00007f5660c9c5cc in thread_canary_free_zombies ()
   from /tmp/pygit2/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so
#15 0x00007f5660c9c5e8 in thread_canary_register ()
   from /tmp/pygit2/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so
#16 0x00007f5660c9c890 in gil_ensure ()
   from /tmp/pygit2/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so
#17 0x00007f5660cbb55e in cffi_call_python ()
   from /tmp/pygit2/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so
#18 0x00007f5660cded6b in _sideband_progress_cb () from /tmp/pygit2/.venv/lib/python3.12/site-packages/pygit2/_libgit2.abi3.so
#19 0x00007f5661189112 in local_counting (stage=1, current=20, total=30, payload=0x5595ba91bf70)
    at /usr/src/debug/dev-libs/libgit2-1.7.1/libgit2-1.7.1/src/libgit2/transports/local.c:543
#20 0x00007f56611300a2 in report_delta_progress (pb=0x5595ba9ff380, count=20, force=false)
    at /usr/src/debug/dev-libs/libgit2-1.7.1/libgit2-1.7.1/src/libgit2/pack-objects.c:942
#21 0x00007f5661130294 in find_deltas (pb=0x5595ba9ff380, list=0x5595ba9058c8, list_size=0x5595baa083a8, window=11, depth=50)
    at /usr/src/debug/dev-libs/libgit2-1.7.1/libgit2-1.7.1/src/libgit2/pack-objects.c:979
--Type <RET> for more, q to quit, c to continue without paging--c
#22 0x00007f5661130965 in threaded_find_deltas (arg=0x5595baa08330)
    at /usr/src/debug/dev-libs/libgit2-1.7.1/libgit2-1.7.1/src/libgit2/pack-objects.c:1134
#23 0x00007f5663ca1069 in start_thread (arg=<optimized out>) at pthread_create.c:444
#24 0x00007f5663d25bb8 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

I suppose this could be a bug in CFFI or CPython as well. I can file a bug for either of them if you'd confirm it's not pygit2.

mgorny commented 9 months ago

This doesn't seem to happen with cffi 1.16.0rc2 anymore, so I guess it was a problem there. I'm sorry for the noise.