Skip to content
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

pygit2 segfault under pytest #3293

Closed
4 tasks done
RazerM opened this issue Mar 9, 2018 · 6 comments
Closed
4 tasks done

pygit2 segfault under pytest #3293

RazerM opened this issue Mar 9, 2018 · 6 comments
Labels
type: bug problem that needs to be addressed

Comments

@RazerM
Copy link

RazerM commented Mar 9, 2018

  • Include a detailed description of the bug or suggestion
    I have a test that causes a segfault when run with pytest, but doesn't when run by python. It happens when passing an empty temporary directory to pygit2.Repository.
# works fine
python3 test_pygit2.py

# segfault
python3 -X faulthandler -m pytest test_pygit2.py
  • pip list of the virtual environment you are using
Package       Version
------------- -------
attrs         17.4.0
cffi          1.11.5
pip           9.0.1
pkg-resources 0.0.0
pluggy        0.6.0
py            1.5.2
pycparser     2.18
pygit2        0.26.3
pytest        3.4.2
setuptools    32.3.1
six           1.11.0
  • pytest and operating system versions
    • macOS 10.12.6
    • Debian buster (so it has the same libgit2 that I have on my mac)
    • pytest 3.4.2
  • Minimal example if possible

File test_pygit.py:

from pygit2 import Repository
import tempfile

def test_segfault():
    with tempfile.TemporaryDirectory() as tmpdir:
        Repository(tmpdir)

if __name__ == '__main__':
    test_segfault()

running under pytest:

# python3 -X faulthandler -m pytest test_pygit2.py
=================================== test session starts ===================================
platform linux -- Python 3.6.4+, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: /, inifile:
collected 1 item

test_pygit2.py Fatal Python error: Segmentation fault

Current thread 0x00007f1f2a1e6740 (most recent call first):
  File "/usr/lib/python3/dist-packages/pygit2/repository.py", line 100 in __repr__
  File "/usr/lib/python3/dist-packages/py/_io/saferepr.py", line 38 in _callhelper
  File "/usr/lib/python3/dist-packages/py/_io/saferepr.py", line 33 in repr_instance
  File "/usr/lib/python3.6/reprlib.py", line 65 in repr1
  File "/usr/lib/python3.6/reprlib.py", line 55 in repr
  File "/usr/lib/python3/dist-packages/py/_io/saferepr.py", line 38 in _callhelper
  File "/usr/lib/python3/dist-packages/py/_io/saferepr.py", line 13 in repr
  File "/usr/lib/python3/dist-packages/py/_io/saferepr.py", line 71 in saferepr
  File "/usr/lib/python3/dist-packages/_pytest/_code/code.py", line 497 in _saferepr
  File "/usr/lib/python3/dist-packages/_pytest/_code/code.py", line 503 in repr_args
  File "/usr/lib/python3/dist-packages/_pytest/_code/code.py", line 580 in repr_traceback_entry
  File "/usr/lib/python3/dist-packages/_pytest/_code/code.py", line 621 in repr_traceback
  File "/usr/lib/python3/dist-packages/_pytest/_code/code.py", line 669 in repr_excinfo
  File "/usr/lib/python3/dist-packages/_pytest/_code/code.py", line 435 in getrepr
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 477 in _repr_failure_py
  File "/usr/lib/python3/dist-packages/_pytest/python.py", line 576 in _repr_failure_py
  File "/usr/lib/python3/dist-packages/_pytest/python.py", line 583 in repr_failure
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 303 in pytest_runtest_makereport
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 614 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 265 in __init__
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 248 in _wrapped_call
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 613 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 334 in <lambda>
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 339 in _hookexec
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 745 in __call__
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 159 in call_and_report
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 77 in runtestprotocol
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 63 in pytest_runtest_protocol
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 614 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 265 in __init__
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 248 in _wrapped_call
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 613 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 265 in __init__
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 248 in _wrapped_call
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 613 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 334 in <lambda>
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 339 in _hookexec
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 745 in __call__
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 170 in pytest_runtestloop
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 614 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 334 in <lambda>
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 339 in _hookexec
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 745 in __call__
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 147 in _main
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 111 in wrap_session
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 140 in pytest_cmdline_main
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 614 in execute
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 334 in <lambda>
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 339 in _hookexec
  File "/usr/lib/python3/dist-packages/_pytest/vendored_packages/pluggy.py", line 745 in __call__
  File "/usr/lib/python3/dist-packages/_pytest/config.py", line 58 in main
  File "/usr/lib/python3/dist-packages/pytest.py", line 73 in <module>
  File "/usr/lib/python3.6/runpy.py", line 85 in _run_code
  File "/usr/lib/python3.6/runpy.py", line 193 in _run_module_as_main
Segmentation fault

running under python, with correct exception:

# python3 test_pygit2.py
Traceback (most recent call last):
  File "test_pygit2.py", line 9, in <module>
    test_segfault()
  File "test_pygit2.py", line 6, in test_segfault
    Repository(tmpdir)
  File "/venv/lib/python3.6/site-packages/pygit2/repository.py", line 1184, in __init__
    path_backend = init_file_backend(path)
_pygit2.GitError: Repository not found at /tmp/tmp_9_aoab1

I'm assuming this is a pytest error since it works when called from Python, but if that's wrong I can file this against pygit2.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Mar 9, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1411 (Pytest stops), #1602 (pytest.print()), #2838 (Contributing to pytest-dev), #1370 (Print out pytest-warnings?), and #528 (Test causes segfault).

@RonnyPfannschmidt
Copy link
Member

whats the output if the test is not running under pytest?

its possible that pygit2 does something that breaks pytests capture mechanism

@RazerM
Copy link
Author

RazerM commented Mar 9, 2018

@RonnyPfannschmidt I have added the output to the main post

@RonnyPfannschmidt
Copy link
Member

based on the posted information its unclear whats at fault here

@RazerM
Copy link
Author

RazerM commented Mar 9, 2018

Ok so Repository.__repr__ is being called by pytest before Repository.__init__ returns, and the C getter for Repository.path tries to use self->repo which isn't initialized. It's a pygit2 bug.

@RazerM RazerM closed this as completed Mar 9, 2018
@RonnyPfannschmidt
Copy link
Member

thanks for following up with the details 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants