Skip to content

Python 3.8+, Fatal Python error: Segmentation fault when calling requests.get(URL, params) with docker python-3.8.2-slim-buster/openssl 1.1.1d and python-3.9.10-slim-buster/openssl 1.1.1d #62

@medero

Description

@medero

Here's the trace:

Python 3.9.10 (main, Mar  1 2022, 21:02:54) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get('https://serpapi.com', {"api_key":VALID_API_KEY, "engine": "google_jobs", "q": "Barista"})
Fatal Python error: Segmentation fault

Current thread 0x0000ffff8e999010 (most recent call first):
  File "/usr/local/lib/python3.9/ssl.py", line 1173 in send
  File "/usr/local/lib/python3.9/ssl.py", line 1204 in sendall
  File "/usr/local/lib/python3.9/http/client.py", line 1001 in send
  File "/usr/local/lib/python3.9/http/client.py", line 1040 in _send_output
  File "/usr/local/lib/python3.9/http/client.py", line 1280 in endheaders
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 395 in request
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496 in _make_request
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 790 in urlopen
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 486 in send
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 703 in send
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 589 in request
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59 in request
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 73 in get
  File "<stdin>", line 1 in <module>
Segmentation fault

This is not specific to one engine, it also applies to google_images if I swap the engine.

Dockerfile:

FROM python:3.9.10-slim-buster

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

# OLD: RUN apt-get update && apt-get upgrade -y && apt-get install gcc -y && apt-get install apt-utils -y

# Install build-essential for celery worker otherwise it says gcc not found
RUN apt-get update \
  # dependencies for building Python packages
  && apt-get install -y build-essential \
  # psycopg2 dependencies
  && apt-get install -y libpq-dev \
  # Additional dependencies
  && apt-get install -y telnet netcat \
  # cleaning up unused files
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY ./compose/local/flask/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

# COPY ./compose/local/flask/celery/worker/start /start-celeryworker
# RUN sed -i 's/\r$//g' /start-celeryworker
# RUN chmod +x /start-celeryworker

# COPY ./compose/local/flask/celery/beat/start /start-celerybeat
# RUN sed -i 's/\r$//g' /start-celerybeat
# RUN chmod +x /start-celerybeat

# COPY ./compose/local/flask/celery/flower/start /start-flower
# RUN sed -i 's/\r$//g' /start-flower
# RUN chmod +x /start-flower

COPY . .

# COPY entrypoint.sh /usr/local/bin/
# ENTRYPOINT ["entrypoint.sh"]

docker-compose.yml:

version: "3.9"

services:
  flask_app:
    restart: always
    container_name: flask_app
    image: meder/flask_live_app:1.0.0
    command: /start
    build: .
    ports:
      - "4000:4000"
    volumes:
      - .:/app
    env_file:
      - local.env
    environment:
      - FLASK_ENV=development
      - FLASK_APP=app.py
    depends_on:
      - db
  db:
    container_name: flask_db
    image: postgres:16.1-alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=USER
      - POSTGRES_PASSWORD=PW
      - POSTGRES_DB=DB
    volumes: 
      - postgres_data:/var/lib/postgresql/data
  redis:
    container_name: redis
    image: redis:7.2-alpine
    ports:
      - "6379:6379"
volumes:
  postgres_data: {}

And requirements.txt though I didn't update requirements.txt after trying 3.9.10 from the original 3.8.2:

flask==3.0.0
psycopg2-binary==2.9.9
google-search-results==2.4.2

The above trace came from bashing into my docker instance and running requests.get after importing it like so:

docker exec -it flask_app bash

The host machine runs this fine, but uses LibreSSL 2.8.3 / Python 3.8.16 - based on other tickets/issues here it seems like there's possibly something on the SSL side of the backend that's triggering this - would appreciate some insight

Someone ran into this on SO and the selected answer was updating the timeout: https://stackoverflow.com/questions/74774784/cheerypy-server-is-timing-out but no guarantee this is the same issue, just a reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions