python: SEGFAULT when certain modules are used in a project with Alpine 3.6/Python 3.6
We’ve recently upgraded several of our containers to Python 3.6.
Some of the containers always segfault immediately after starting Django’s runserver
command.
In a couple of the containers upgrading our dependencies fixed the issue, but on some of the other containers that didn’t have the issue upgrading the dependencies caused it to start happening.
In one example upgrading requests
from 2.12.1 to 2.18.1 stopped the SEGFAULTs but adding the latest version of boto3
caused them to start again.
The issue only happens when run under docker.
I have a simple example repo here and would like to offer a bounty of $100 to whoever can either fix the issue or explain it in a way that allows me to fix it. ✨
Edit: we’ve tested with 3-alpine
and 3-alpine3.6
; same result.
Also SEGFAULTs on 3.6.2rc2-alpine3.6
.
More clues: requests
is also implicated in boto3
which includes botocore
–which includes a vendored requests
2.7.0.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 29 (5 by maintainers)
Commits related to this issue
- Update to Alpine:3.6 (and python3.6) Need to include a hack to solve a problem with running runserver in python3.6. Check for more info: https://github.com/docker-library/python/issues/211 — committed to jaimebuelta/django-docker-template by deleted user 7 years ago
- Added a workaround for Alpine Linux to avoid Python segfaults (https://github.com/docker-library/python/issues/211) — committed to frol/flask-restplus-server-example by frol 7 years ago
- main/python3: increase thread stack size we segfault before we hit the sys.getrecurslimit(), which is bad. Some testing showed that to be able to reach the default sys.getrecurslimit(), which is 1000... — committed to alpinelinux/aports by ncopa 7 years ago
- Alpine: Ensure thread stack size is large enough (#211) — committed to JayH5/python by JayH5 7 years ago
- Alpine: Ensure thread stack size is large enough (#211) — committed to JayH5/python by JayH5 7 years ago
- Alpine: Ensure thread stack size is large enough (#211) — committed to JayH5/python by JayH5 7 years ago
- Fix segfaults when running paster Fixes #2 I nailed down the segmentation faults occurring to using the development server (Paster, --reload option didn't affect). Of course I don't know the exact i... — committed to okfn/docker-ckan by amercader 6 years ago
- Fixes python3 segfaults on OpenResty alpine images See https://github.com/docker-library/python/issues/211 — committed to openresty/docker-openresty by deleted user 6 years ago
- Alpine: Ensure thread stack size is large enough (#211) — committed to tao12345666333/python by JayH5 7 years ago
- Fix segfault issue in docker by patching salt-call This patch updates the threading stack size to 8MB. see: https://github.com/docker-library/python/issues/211#issuecomment-338513417 — committed to bbinet/salt-thin-setupify by bbinet 4 years ago
awesome! Please donate it to Doctors Without Borders or a similar charity.
finally verifying that I made that donation ✨
I have solved SEGFAULT issue by adding this code to my python script:
It looks to me that this code does the same job as xyzz’s solution but in python. I found this solution on https://github.com/esnme/ultrajson/issues/254
@xyzz done! i assume I’ll get some confirmation once it goes through (I did it through work) and am happy to send that along when I get it 😃
also: do you happen to know where the best place to escalate this issue might be? it seems like an ‘alpine’s use of musl’ issue, correct?
@sobolevn It works fine with alpine 3.7 so if you can, just upgrade switch to it.
@xyzz that works! where shall I send your $100? 😃
The same here. I have a segfault when running
from rest_framework import routers
. Link to theDockerfile
: https://github.com/wemake-services/wemake-django-template/blob/master/{{cookiecutter.project_name}}/docker/django/DockerfileRight now I am using
--noreload
option forrunserver
, since it only affects my development containers.A couple pointers, don’t install
python3
orpython3-dev
from apk if you are using the python docker image. The python in the docker image is installed from source so anything that links to or uses the apk installed python will probably have issues. But this is not the source of the segfault.Don’t remove dependencies in a later
RUN
line as this won’t save any image size. Don’tapk update
on its ownRUN
line (use&&
to chain it to the command using it). Don’tapk upgrade
in a container; it is best to wait for the base image to update.Following are the two Dockerfiles that I ran your compose on; both still segfault. The first is using just the python provided in the docker python image (alpine based). The second is using python3 from Alpine Linux (
apk
). So, my opinion is that this is not a bug in the docker python image, but I would suspect is one of the “package expectsglibc
but hasmuslc
” as noted on the readme from Docker Hub. Therefore, it is most likely to need a fix in python upstream or muslc. @ncopa, do you think you could help debug where the fix is needed?This Dockerfile, on the other hand, works fine.