5 days ago
My Dockerized Python app (using Gunicorn and Playwright) is repeatedly experiencing the following issues:
Gunicorn Worker Timeouts:
Workers are timing out and being SIGKILL'ed (likely due to out-of-memory or long tasks).
Example logs:
CopyEdit
[CRITICAL] WORKER TIMEOUT (pid: X) [ERROR] Worker (pid: X) was sent SIGKILL! Perhaps out of memory?
Playwright Failing to Launch Chromium:
Error during scraping:
BrowserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium_headless_shell...
The error suggests that Playwright was just installed but the required browser wasn't downloaded.
Logs prompt to run
playwright install
, even though the Dockerfile runs:CopyEdit
RUN /code/.venv/bin/python -m playwright install --with-deps chromium
Docker Environment:
Base image:
python:3.12-slim-bookworm
Playwright installed inside a Poetry-managed virtualenv.
Browser install attempted via:
/code/.venv/bin/python -m playwright install --with-deps chromium
Request:
Clarify why the Playwright Chromium binary is not found despite explicit installation in the Dockerfile.
Clarify how should I properly install Playwright
Advise on preventing Gunicorn worker timeouts or confirm if OOM errors are the cause.
I have attached the dockerfile content
this is the error I see in the railways logs
[2025-07-27 02:17:09 +0000] [1] [INFO] Starting gunicorn 23.0.0 [2025-07-27 02:17:09 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1) [2025-07-27 02:17:09 +0000] [1] [INFO] Using worker: sync [2025-07-27 02:17:09 +0000] [5] [INFO] Booting worker with pid: 5 [2025-07-28 04:40:05 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:5) [2025-07-28 04:40:16 +0000] [1] [ERROR] Worker (pid:5) was sent SIGKILL! Perhaps out of memory? [2025-07-28 04:40:16 +0000] [6] [INFO] Booting worker with pid: 6 [2025-07-30 09:45:45 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:6) [2025-07-30 09:45:51 +0000] [1] [ERROR] Worker (pid:6) was sent SIGKILL! Perhaps out of memory? [2025-07-30 09:45:55 +0000] [7] [INFO] Booting worker with pid: 7 [2025-07-30 18:43:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:7) [2025-07-30 18:43:26 +0000] [7] [INFO] Worker exiting (pid: 7) [2025-07-30 18:43:27 +0000] [1] [ERROR] Worker (pid:7) exited with code 1 [2025-07-30 18:43:27 +0000] [1] [ERROR] Worker (pid:7) exited with code 1. [2025-07-30 18:43:27 +0000] [8] [INFO] Booting worker with pid: 8 Error scraping Amazon product https://www.amazon.com/ASUS-ROG-Strix-Gaming-Laptop/dp/B0DZZWMB2L/ref=sr_1_2?_encoding=UTF8&sr=8-2: BrowserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell ╔════════════════════════════════════════════════════════════╗ ║ Looks like Playwright was just installed or updated. ║ ║ Please run the following command to download new browsers: ║ ║ ║ ║ playwright install ║ ║ ║ ║ <3 Playwright Team ║ ╚════════════════════════════════════════════════════════════╝ Error scraping Amazon product https://www.amazon.com/ASUS-ROG-Strix-Gaming-Laptop/dp/B0DZZWMB2L/ref=sr_1_2?_encoding=UTF8&sr=8-2: BrowserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell ╔════════════════════════════════════════════════════════════╗ ║ Looks like Playwright was just installed or updated. ║ ║ Please run the following command to download new browsers: ║ ║ ║ ║ playwright install ║ ║ ║ ║ <3 Playwright Team ║ ╚════════════════════════════════════════════════════════════╝Thank you very much!
Attachments
3 Replies
5 days ago
Hey there! We've found the following might help you get unblocked faster:
🧵 Got Playwright error: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1161/chrome
🧵 All builds failing (possible connection to Ubuntu servers being down or Chromium infrastructure)
If you find the answer from one of these, please let us know by solving the thread!
mezzoforteprivilege
Based on the logs and the context you've provided, you're facing two distinct but related issues. Let's break down the causes and solutions for each.Issue 1: Playwright Browser Executable MissingThis is the most critical error preventing your application from running its core function.Root Cause:The problem is almost certainly a mismatch between the user context during the Docker build (RUN) and the user context at runtime (CMD).Build Time: When your Dockerfile executes RUN /code/.venv/bin/python -m playwright install ..., it runs this command as the root user by default. Therefore, the Chromium browser is downloaded to the root user's cache directory: /root/.cache/ms-playwright/.Run Time: When your container starts, Gunicorn and your Python application are likely running as a different, non-root user for security reasons. This is a common and recommended practice. This non-root user (e.g., nobody, appuser, etc.) does not have permission to access /root/.cache/ and looks for the browser in its own home directory (e.g., /home/appuser/.cache/), where it doesn't exist.This explains why the installation "succeeds" during the build but the executable is "missing" at runtime.
5 days ago
thanks for the reply, do you know how should I install or modify the dockercompose file?thanks
admsehrglobal
thanks for the reply, do you know how should I install or modify the dockercompose file?thanks
5 days ago
Can you try this Dockerfile ?
Also do check the memory limit in your service settings and temporarily set it to something generous
FROM python:3.12-slim-bookworm
ENV PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_VIRTUALENVS_CREATE=true \
ENV_STATE=production \
PYTHONFAULTHANDLER=1 \
# Playwright environment variables
PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0 \
# Memory optimization environment variables
MALLOC_ARENA_MAX=2 \
MALLOC_MMAP_THRESHOLD_=131072 \
MALLOC_TRIM_THRESHOLD_=131072 \
MALLOC_TOP_PAD_=131072 \
MALLOC_MMAP_MAX_=65536 \
# Python memory optimization
PYTHONMALLOC=malloc
WORKDIR /code
# Install system dependencies
RUN apt-get update && apt-get install -y \
dos2unix \
curl \
# Python compilation dependencies
libpq-dev \
gcc \
python3-dev \
libmagic1 \
# Playwright browser dependencies
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libatspi2.0-0 \
libxshmfence1 \
# Font and display dependencies
fonts-liberation \
fonts-noto-color-emoji \
libcurl4 \
libgtk-3-0 \
libpango-1.0-0 \
libcairo2 \
libdbus-1-3 \
xvfb \
# OpenGL dependencies
libgl1-mesa-glx \
libegl1 \
libgles2 \
# X11 dependencies
libx11-xcb1 \
libxcursor1 \
libxi6 \
libxtst6 \
# Clean up apt cache to reduce image size
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Install Poetry
RUN pip install --no-cache-dir poetry==1.7.1
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Install project dependencies
RUN poetry install --no-interaction --no-ansi $(test "$ENV_STATE" == production && echo "--no-dev") \
&& poetry cache clear pypi --all
# Create Playwright browsers directory with proper permissions
RUN mkdir -p /ms-playwright \
&& chmod 755 /ms-playwright
# Install Playwright and browsers using the virtual environment
RUN /code/.venv/bin/python -m playwright install --with-deps chromium \
&& /code/.venv/bin/python -m playwright install-deps chromium
# Verify Playwright installation and list installed browsers
RUN echo "Verifying Playwright installation..." \
&& ls -la /ms-playwright/ \
&& /code/.venv/bin/python -c "from playwright.sync_api import sync_playwright; print('Playwright installed successfully')"
# Set proper ownership and permissions for the Playwright cache
RUN chown -R root:root /ms-playwright \
&& find /ms-playwright -type d -exec chmod 755 {} \; \
&& find /ms-playwright -type f -exec chmod 644 {} \;
# Copy application code
COPY . .
# Fix line endings and set proper permissions
RUN dos2unix /code/start-django.sh \
&& chmod +x /code/start-django.sh \
&& mkdir -p /code/media /code/staticfiles \
&& chmod -R 755 /code/media /code/staticfiles
# Expose the application port
EXPOSE 8000
# Set the entrypoint
ENTRYPOINT ["bash", "/code/start-django.sh"]