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.

Segfault with black 22.1.0

See original GitHub issue

Describe the bug

When running black with a self-built Python 3.10 I get a segfault.

To Reproduce

Can be reproduced in Docker:

#Dockerfile
FROM ubuntu:20.04

RUN sed -i '/deb-src/s/^# //' /etc/apt/sources.list
RUN apt-get update

ARG DEBIAN_FRONTEND=noninteractive 
ARG TZ=UTC

RUN apt-get build-dep -y python3

# https://devguide.python.org/setup/#install-dependencies
RUN apt-get install -y build-essential gdb lcov pkg-config \
      libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \
      libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
      lzma lzma-dev tk-dev uuid-dev zlib1g-dev

RUN apt-get -y install curl

RUN curl -o Python-3.10.2.tar.xz https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz
RUN tar xf Python-3.10.2.tar.xz
RUN cd Python-3.10.2 \
  && ./configure --with-pydebug --with-ensurepip \
  && make \
  && make altinstall

RUN adduser myuser
RUN mkdir -p /var/blacktest
RUN chown myuser:myuser /var/blacktest

ENV PATH /usr/local/bin:${PATH}

USER myuser
WORKDIR /var/blacktest
COPY Pipfile Pipfile
RUN pip3.10 install pipenv
RUN python3.10 -m pipenv install --dev

Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]
black = "*"

[requires]
python_version = "3.10"

Then running black leads to a segfault error

$ docker build -t blacktest .
$ docker run --rm -it blacktest
myuser@c19751e02d87: python3.10 -m pipenv shell
(blacktest) myuser@c19751e02d87:/var/blacktest$ black
Objects/typeobject.c:5970: type_ready_checks: Assertion "type->tp_call != ((void *)0)" failed
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x559372c83ca0
object refcount : 1
object type     : 0x55937285cea0
object type name: type
object repr     : Segmentation fault (core dumped)

Expected behavior

Black should not lead to a segfault.

Environment

  • Black’s version: 22.1.0
  • OS and Python version: Ubuntu 20.04, Python 3.10 (built from source, see above)

** Further remarks **

Curiously, I could run the tests as instructed without errors.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ichard26commented, Sep 2, 2022

https://github.com/python/mypy/pull/13152 fixes this, but it hasn’t made its way into a mypy release yet. The next release is being tracked in https://github.com/python/mypy/issues/13385 but it seems to be behind schedule (as usual for mypy). Once mypy cuts a new release I’ll upgrade our mypy[c] cibuildwheel requirement, resolving this.

1reaction
ichard26commented, Jan 31, 2022

The crash is almost certainly related to our use of mypyc. Thus, a workaround could be to install from source (I think --no-binary :all: is the right pip option). Also, maybe there’s already a known issue over at https://github.com/mypyc/mypyc that explains what we’re seeing.

I recommend using --no-binary black instead of blocklisting all wheels from deps to minimize build time issues even from Pure Python packages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What causes a Python segmentation fault? - Stack Overflow
This happens when a python extension (written in C) tries to access a memory beyond reach. You can trace it in following ways....
Read more >
Mesa 22.1.0 Release Notes / 2022-05-18
Mesa 22.1.0 is a new development release. People who are concerned with stability and reliability should stick with a previous release or ...
Read more >
Nouveau NV4A glxgears segmentation fault (#6639) · Issues
I am running glxgears on GeForce6200 (NV4A) and I am getting segmentation fault after a black window is displayed.
Read more >
Bug#1007992: libigdgmm12: new version causes segfaults
Mar 20 04:30:17 heisenberg kernel: mpv/vo[292810]: segfault at 300000200 ip 00007f93a01e49ae sp 00007f93ab2514b0 error 4 in ...
Read more >
Issue 4313: IDLE segfault at exit - Python tracker
10 0 -foreground 1 black 2 -selectforeground 3 black 4 -selectbackground 5 black 6 -background 7 black 8 -insertbackground 9 Traceback (most ...
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