-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
SEGFAULT when certain modules are used in a project with Alpine 3.6/Python 3.6 #211
Comments
Can you check this ultrajson/ultrajson#254 (comment) |
A couple pointers, don't install Don't remove dependencies in a later 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 ( FROM python:3.6-alpine3.6
# logging to the console breaks without this
ENV PYTHONUNBUFFERED 1
ENV PYTHONFAULTHANDLER 1
RUN apk add --no-cache \
bash \
build-base \
gettext \
linux-headers \
musl-dev \
postgresql-client \
postgresql-dev
RUN mkdir -p /app/
WORKDIR /app/
# so we can cache the installed python modules apart from the app files
COPY *.txt /app/
RUN pip3 install --upgrade pip setuptools
RUN pip3 install -r requirements.txt -r dev-requirements.txt
COPY . /app/ FROM alpine:3.6
# logging to the console breaks without this
ENV PYTHONUNBUFFERED 1
ENV PYTHONFAULTHANDLER 1
RUN apk add --no-cache \
bash \
build-base \
gettext \
linux-headers \
musl-dev \
postgresql-client \
postgresql-dev \
python3 \
python3-dev \
# alpine doesn't provide a `python` symlink to `python3`, so create your own
&& ln -s /usr/bin/python3 /usr/local/bin/python
RUN mkdir -p /app/
WORKDIR /app/
# so we can cache the installed python modules apart from the app files
COPY *.txt /app/
RUN pip3 install --upgrade pip setuptools
RUN pip3 install -r requirements.txt -r dev-requirements.txt
COPY . /app/ This Dockerfile, on the other hand, works fine. # Debian based image
FROM python:3.6
RUN mkdir -p /app/
WORKDIR /app/
# so we can cache the installed python modules apart from the app files
COPY *.txt /app/
RUN pip3 install --upgrade pip setuptools
RUN pip3 install -r requirements.txt -r dev-requirements.txt
COPY . /app/ |
@yosifkit good catch on not installing re: the other Docker optimizations, thanks! I have more reading to do I guess :) |
@xyzz I implemented your changes here; I still get a segfault: https://github.com/beaugunderson/crash-test/compare/bg-stack-fix is there a way to test that LD_PRELOAD is working correctly? I don't see any output for the |
|
oof, simple typo! thanks :) |
@xyzz that works! where shall I send your $100? :) |
awesome! Please donate it to Doctors Without Borders or a similar charity. |
@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? |
I've already poked an alpine developer about it, I think they will patch python to use bigger stack argument in |
thanks so much!
…---
Sent from my phone.
On Jul 12, 2017, at 15:49, xyzz ***@***.***> wrote:
I've already poked an alpine developer about it, I think they will patch python to use bigger stack argument in pthread_create.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I'll close this issue since I don't think there's anything to be done here :) I'll also add this link to a previous discussion of increasing the stack size in musl just to provide another concrete example. |
Need to include a hack to solve a problem with running runserver in python3.6. Check for more info: docker-library/python#211
I have solved SEGFAULT issue by adding this code to my python script: import threading; threading.stack_size(2*1024*1024) It looks to me that this code does the same job as xyzz's solution but in python. I found this solution on ultrajson/ultrajson#254 |
@fadawar this fix improves the SEGFAULT behavior for my containers but doesn't fix it entirely... I go from an immediate SEGFAULT on launch to a few SEGFAULTs a day; not sure why there's a difference! but I have to go back to the old fix |
Interesting, I have been using Python 3 in Alpine Docker image ( Here is the reproduction:
When I query
Setting a bigger stack size suggested by @fadawar solves the issue (or at least masks the problem for now). I have tested the behaviour on a few different hosts because I thought that it might have been related to the kernel (all resulted in the same segfault):
Interestingly, if I rebase on The project which I reproduce this issue on is public, so you can play with it: https://github.com/frol/flask-restplus-server-example (I have added the hotfix |
Wow, would never have thought to end up here. I've been hunting a bug in my Django code for almost a week and finally just nailed it down to Thanks @fadawar for the snippet. That makes my code work again. So what is the status with this bug now -- will we need to wait for a fix in |
The same here. I have a segfault when running Right now I am using |
Does it make any difference if you add |
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, we need at least a 453k stack on x86_64. We set it to 1MB so we have a bit extra. It is also worth to note that upstream set stacksize to 4MB on freebsd and 5MB on OSX. ref #8134 docker-library/python#211
@ncopa I tried it, but it still crashes for me. |
@ncopa no luck either. |
@sobolevn It works fine with alpine 3.7 so if you can, just upgrade switch to it. |
@IlianIliev does that mean the LD_PRELOAD hack isn't needed at all with Alpine 3.7? |
@davidwindell exactly. I just updated to Alpine 3.7, installed python 3 and it was working like a charm. |
With the latest |
@JayH5 is this also fixed on |
@davidwindell yup, Python 2.7 as well. See #211. |
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 issue with paster but the underlying issue seems to be Alpine 3.6 + some python packages + a too small stack size. docker-library/python#211 There are several issues across different projects that confirm that upgrading to Alpine 3.7 solves the issue, so that's what we did. The upgrade to Alpine 3.7 caused the following issues: * curl was not part of the image by default, added it to the installed packages * psycopg2 build failed because of: psycopg/psycopg2#594 The fix is to upgrade the psycopg2 version. This is hardcoded in CKAN's requirements.txt so we work around it changing the version when building the image (this should be upgraded in CKAN core) Also for good measure we don't use binaries when building the requirements because of the issues described here: ckan/ckan#3893
I'm using |
@fr0der1c Please open a new issue. I don't think it is same problem.
No segfault here... |
This patch updates the threading stack size to 8MB. see: docker-library/python#211 (comment)
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 ofboto3
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
and3-alpine3.6
; same result.Also SEGFAULTs on
3.6.2rc2-alpine3.6
.More clues:
requests
is also implicated inboto3
which includesbotocore
--which includes a vendoredrequests
2.7.0.The text was updated successfully, but these errors were encountered: