gunicorn/tests/docker/asgi_compliance/Dockerfile.gunicorn
Benoit Chesneau e780508f56 fix: resolve ASGI concurrent request failures through nginx proxy
- Fix nginx config to use keepalive with upstream (was sending
  Connection: close which caused premature connection closure)
- Add _safe_write() to handle socket errors (EPIPE, ECONNRESET,
  ENOTCONN) gracefully when client disconnects
- Fix ASGI scope server/client to always be 2-tuples for IPv6
  compatibility (IPv6 sockets return 4-tuples)
- Add write_eof() before close() to ensure buffered data is flushed
- Bind to [::] for dual-stack IPv4/IPv6 support in test containers
2026-02-06 01:57:28 +01:00

56 lines
1.5 KiB
Docker

FROM python:3.12-slim
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy the gunicorn source code and install it with all extras
COPY . /gunicorn-src/
RUN pip install --no-cache-dir /gunicorn-src/[http2,testing]
# Install additional ASGI frameworks for testing
RUN pip install --no-cache-dir \
starlette>=0.35.0 \
fastapi>=0.109.0 \
websockets>=12.0
# Copy the test applications
COPY tests/docker/asgi_compliance/apps /app/apps
# Create entrypoint script
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
if [ "$USE_SSL" = "1" ]; then\n\
exec gunicorn "apps.main_app:app" \\\n\
--bind "[::]:8443" \\\n\
--worker-class "asgi" \\\n\
--workers 2 \\\n\
--worker-connections 1000 \\\n\
--certfile "/certs/server.crt" \\\n\
--keyfile "/certs/server.key" \\\n\
--asgi-disconnect-grace-period 0 \\\n\
--log-level "debug" \\\n\
--access-logfile "-" \\\n\
--error-logfile "-"\n\
else\n\
exec gunicorn "apps.main_app:app" \\\n\
--bind "[::]:8000" \\\n\
--worker-class "asgi" \\\n\
--workers 2 \\\n\
--worker-connections 1000 \\\n\
--asgi-disconnect-grace-period 0 \\\n\
--log-level "debug" \\\n\
--access-logfile "-" \\\n\
--error-logfile "-"\n\
fi\n\
' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh
EXPOSE 8000 8443
CMD ["/app/entrypoint.sh"]