playwright-python icon indicating copy to clipboard operation
playwright-python copied to clipboard

[Bug]: If resources are too small, browser objects will crash

Open tynam-yang opened this issue 1 year ago • 5 comments

Version

1.42

Steps to reproduce

I run a playwright in k8s, and headless=True: 1、Resources: CPU set to 1, memory set to 1 2、When opening a new page or executing context.new_page()

Expected behavior

Program running

Or a recommended minimum resource is specified

Actual behavior

Exception thrown: playwright._impl._errors.Error: Target crashed

Additional context

When I set resource CPU to 2 and memory to 2, the program works fine

Environment

- platform: Linux
- Python Version: 3.10.14
- pytest Version: 8.0.2
- Browser: Chrome

tynam-yang avatar Jun 12 '24 03:06 tynam-yang

Would it be possible to share a script with us / minimal reproducible which we can run locally?

Thank you!

mxschmitt avatar Jun 12 '24 08:06 mxschmitt

I encountered similar errors

tython avatar Jun 14 '24 05:06 tython

1.The dockerfile is as follows

`FROM mcr.microsoft.com/playwright/python:v1.44.0-jammy

LABEL maintainer="[email protected]" version="0.1"

WORKDIR /app

RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone &&
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

RUN pip install --upgrade pip &&
pip install poetry

COPY pyproject.toml poetry.lock ./

RUN poetry config virtualenvs.create false &&
poetry install --no-dev --no-interaction --no-ansi

ENV PATH="/app/.venv/bin:$PATH"

RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak

RUN sed -i '[email protected]/@mirrors.aliyun.com/@g' /etc/apt/sources.list &&
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list &&
sed -i '[email protected]/@mirrors.aliyun.com/@g' /etc/apt/sources.list

RUN apt-get update &&
apt-get install -y
libglib2.0-0
libnss3
libnspr4
libdbus-1-3
libatk1.0-0
libatk-bridge2.0-0
libcups2
libdrm2
libatspi2.0-0
libx11-6
libxcomposite1
libxdamage1
libxext6
libxfixes3
libxrandr2
libgbm1
libxcb1
libxkbcommon0
libpango-1.0-0
libcairo2
libasound2
vim
wget
curl
iproute2
iputils-ping
ttf-wqy-microhei &&
rm -rf /var/lib/apt/lists/*

COPY . .

CMD ["python", "./main.py"]`

2.Run container docker run -it --rm -v /etc/hosts:/etc/hosts --ipc=host qingcloud/qingcloud-playwright:v0.4 /bin/bash

3.Execute tests within docker python main.py

image

image

tython avatar Jun 14 '24 05:06 tython

Resources: CPU set to 1, memory set to 1. I didn't repeat it.

I started by using page_fixture to open a browser.

If i open a browser using student_page_fixture during the execution, Target crashed occurs

image

Adjust resources when solving a solution: image

tynam-yang avatar Jun 14 '24 06:06 tynam-yang

Would it be possible to share some something which we can execute locally? Ideally a docker run command which fails? 1 GB should be enough for basic sites.

mxschmitt avatar Jun 14 '24 11:06 mxschmitt

Closing since its stale. This doesn't like a Playwright bug in particular. We recommend giving the containers more cpu/memory which should help for that scenario. Setting the DEBUG=pw:browser env might yield more debug output, why Chromium isn't able to launch / crashing.

mxschmitt avatar Jul 05 '24 10:07 mxschmitt