Skip to content

[Bug]: context.new_page() hangs indefinitely in Docker (Playwright v1.55.0-noble on Ubuntu 22.04.5 host) #2987

@7evf0

Description

@7evf0

Version

1.55.0

Steps to reproduce

  1. Insert the given test file:
  • This test has been experimented on my personal Ubuntu 22.04.5 TLS VPS with the custom Docker image built from mcr.microsoft.com/playwright/python:v1.55.0-noble.
import time
import pytest
from playwright.sync_api import Browser, sync_playwright
import logging, os

logger = logging.getLogger("course_checker")

if not logger.handlers:
    handler = logging.StreamHandler()
    handler.setFormatter(logging.Formatter("%(asctime)s | %(levelname)s | %(name)s | %(message)s"))
    logger.addHandler(handler)

logger.setLevel(os.getenv("LOG_LEVEL", "INFO").upper())

@pytest.fixture(autouse=True)
def _configure_test_logging():
    # reduce noise from Playwright during tests
    logging.getLogger("playwright").setLevel(logging.WARNING)
    yield

@pytest.mark.timeout(30)
def test_new_page_does_not_hang():
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=True, args=["--disable-dev-shm-usage"])
        logger.info("Browser launched for test")
        context = browser.new_context()
        logger.info("Context created for test")
        try:
            page = context.new_page()
            logger.info("Page created for test")
            page.close()
        finally:
            context.close()
            browser.close()
  1. Configure the Dockerfile and docker-compose.yml:
  • Dockerfile
    FROM mcr.microsoft.com/playwright/python:v1.55.0-noble
    WORKDIR /app
    USER root
    ENV PIP_NO_CACHE_DIR=1 \
        PYTHONUNBUFFERED=1 \
        LOG_LEVEL=INFO \
        HEADLESS=true
    COPY requirements.txt /app/requirements.txt
    RUN python -m pip install --no-cache-dir --upgrade -r /app/requirements.txt
    COPY app.py course_manager.py /app/
    COPY tests/ /app/tests/
    USER pwuser
    CMD ["pytest", "-s"]
  • docker-compose.yml
services:
  course_checker:
    build:
      context: .
      dockerfile: Dockerfile
    env_file: .env
    ipc: host
  • requirements.txt
playwright==1.55.0
python-dotenv
pytest
pytest-playwright
pytest-timeout
  1. Run the test in the Docker container:
>> docker compose up --build

Expected behavior

  • The expected output of the testcase with the logs is given below. The given output is experimented in Windows 11 with the same Docker environment and configurations.
======================== test session starts =========================
platform linux -- Python 3.12.3, pytest-8.4.2, pluggy-1.6.0
rootdir: /app
plugins: timeout-2.4.0, base-url-2.1.0, playwright-0.7.1
collected 1 item                                                  

2025-10-05 12:42:26,890 | INFO | course_checker | Browser launched for test
2025-10-05 12:42:26,906 | INFO | course_checker | Context created for test
2025-10-05 12:42:27,847 | INFO | course_checker | Page created for test
.

========================= 1 passed in 2.52s ==========================

Actual behavior

  • The page creation operation hangs forever. For the experimental purposes, the timeout duration is decided as 30 seconds, as seen on the test script.

  • The given output is experimented in Ubuntu 22.04.5 TLS with the same Docker environment and configurations given above.

  • The actual behavior with the timeout logs are given below.

course_checker-1  | ============================= test session starts ==============================
course_checker-1  | platform linux -- Python 3.12.3, pytest-8.4.2, pluggy-1.6.0
course_checker-1  | rootdir: /app
course_checker-1  | plugins: timeout-2.4.0, base-url-2.1.0, playwright-0.7.1
course_checker-1  | collected 1 item
course_checker-1  |
course_checker-1  | 2025-10-05 09:41:53,153 | INFO | course_checker | Browser launched for test
course_checker-1  | 2025-10-05 09:41:53,191 | INFO | course_checker | Context created for test
course_checker-1  | tests/test_new_page.py +++++++++++++++++++++++++++++++++++ Timeout ++++++++++++++++++++++++++++++++++++
course_checker-1  | ~~~~~~~~~~~~~~~~~ Stack of asyncio-waitpid-0 (140343497283264) ~~~~~~~~~~~~~~~~~
course_checker-1  |   File "/usr/lib/python3.12/threading.py", line 1030, in _bootstrap
course_checker-1  |     self._bootstrap_inner()
course_checker-1  |   File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
course_checker-1  |     self.run()
course_checker-1  |   File "/usr/lib/python3.12/threading.py", line 1010, in run
course_checker-1  |     self._target(*self._args, **self._kwargs)
course_checker-1  |   File "/usr/lib/python3.12/asyncio/unix_events.py", line 1408, in _do_waitpid
course_checker-1  |     pid, status = os.waitpid(expected_pid, 0)
course_checker-1  | +++++++++++++++++++++++++++++++++++ Timeout ++++++++++++++++++++++++++++++++++++

Additional context

  • The same test and code run successfully on my local Windows 11 machine (with the same Docker environment) but hang on the VPS environment (Ubuntu 22.04.5 LTS).

  • Runtime resource snapshots from the VPS (docker stats):

During hang:

  • Mem: 140.6 MiB / 1 GiB (13.7%)
  • PIDs: 53
  • CPU: ~0%

After pytest-timeout fires:

  • Mem: 140.3 MiB / 1 GiB (13.7%)
  • PIDs: 53
  • CPU: ~98%

Environment

- Operating System: [Ubuntu 24.04 LTS Noble Numbat (Docker Env) - Ubuntu 22.04.5 TLS (Running on VPS)]
- CPU: [x86_64 (1 vCPU) – Intel® Xeon® Silver 4214 @ 2.20 GHz]
- Browser: [Chromium]
- Python Version: [3.12.3]
- Other info: Running inside Docker container on this VPS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions