question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SIGSEGV when Python tests use the `ctypes` module

See original GitHub issue

Description:

When using the Python installed with this action I run into SIGSEGV on Linux if my tests use ctypes. This is is the offending workflow

name: Tests
on: push
concurrency: 
  group: ${{ github.head_ref || github.run_id }}
  cancel-in-progress: true
jobs:
  tests-linux:
    runs-on: ubuntu-latest
    
    strategy:
      fail-fast: false
      matrix:
        python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
    
    env:
      AUSTIN_TESTS_PYTHON_VERSIONS: ${{ matrix.python-version }}
    
    name: Tests on Linux with Python ${{ matrix.python-version }}
    steps:
      - uses: actions/checkout@v2

      - name: Install build dependencies
        run: |
          sudo apt-get -y install libunwind-dev binutils-dev libiberty-dev

      - name: Install test dependencies
        run: |
          sudo apt-get -y install \
            valgrind \
            gdb

      - name: Install Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install Python 3.10
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Compile Austin
        run: |
          autoreconf --install
          ./configure --enable-debug-symbols true
          make

      - name: Run tests
        run: |
          ulimit -c unlimited
          python3.10 -m venv .venv
          source .venv/bin/activate
          pip install --upgrade pip
          pip install -r test/requirements.txt
          sudo -E .venv/bin/pytest --pastebin=failed --no-flaky-report -sr a -n auto
          .venv/bin/pytest --pastebin=failed --no-flaky-report -sr a -n auto
          deactivate

If Python is installed from, e.g., deadsnakes/ppa, then the tests pass without SIGSEGV. I can also get the tests to pass locally.

This is an example of a happy workflow that pulls Python from the PPA: https://github.com/P403n1x87/austin/runs/7046194671?check_suite_focus=true

This is a run with the action: https://github.com/P403n1x87/austin/runs/7045119660?check_suite_focus=true

This was discovered with this PR: https://github.com/P403n1x87/austin/pull/120/files

Action version:

v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

Repro steps:

See description above

Expected behavior:

No SIGSEGV, like with the Pythons from the PPA.

Actual behavior:

SIGSEGV if ctypes is used

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:28 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
dsamecommented, Jul 22, 2022

@P403n1x87 Status update.

The problem has been reproduced on simplified code:

def test_queue_item():
    value = C.malloc(16)
    C.free(value)
1reaction
dsamecommented, Jun 28, 2022

@P403n1x87 thanks a lot for the backtrace, now i see a SEGFAULT is caused by an instruction of from /lib/x86_64-linux-gnu/libffi.so.7

It is known problem: toolcache python is built against libffi.so.6 which does not exist in ubuntu-20.04

While we are providing the solution, please try to add the step installing libffi.so.6 before running tests as workaround

        - run: |
            curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
            sudo dpkg -i libffi6_3.2.1-8_amd64.deb
            sudo ln -sf libffi.so.6.0.4 /usr/lib/x86_64-linux-gnu/libffi.so
Read more comments on GitHub >

github_iconTop Results From Across the Web

Segmentation fault on gc , using ctypes - python - Stack Overflow
I am calling a native c library using ctypes, passing in a specialiezed struct and getting back another struct. I get a seg...
Read more >
importing "ctypes" immediately causes a segmentation fault
import ctypes Segmentation fault I have found a similiar issue here: https://bugs.python.org/issue11048 But the changes are already applied ...
Read more >
When C extensions crash: easier debugging for your Python ...
The Python standard library has a handy module called faulthandler that can print a traceback when a segfault occurs—that is, when a C...
Read more >
674206 – python ctypes segmentation fault - Red Hat Bugzilla
Description of problem: Python crashes with a segmentation fault when using the ctypes module on RHEL 6 ppc64. It works fine on x86_64...
Read more >
Running C unit tests with pytest - The Hub of Heliopolis
Why use a Python testing framework to test C code? ... Thankfully, the Python standard library comes with the ctypes module that allows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found