[microsoft/playwright][BUG] 基于 ubuntu jammy 的图像上的 webkit 超时

2024-05-09 403 views
2
解决方法

使用Ubuntu 22运行Ubuntu 22(jammy)容器,即可运行。使用 Ubuntu 20 运行它不会工作并导致此问题。如果您遇到此问题,请投票,这有助于我们确定优先级。


语境:

  • 剧作家版本:1.23.0
  • 操作系统:Linux
  • Python版本:3.10
  • 浏览器:Webkit

代码片段 pw.py

import asyncio
from playwright.async_api import async_playwright

async def run():
    async with async_playwright() as playwright:
        await playwright.webkit.launch(headless=True)

if __name__ == "__main__":
    asyncio.run(run())

Dockerfile

FROM snakepacker/python:3.10

RUN apt-install python3-pip && \
    pip install playwright==1.23.0 && \
    playwright install --with-deps webkit

ADD ./pw.py pw.py
CMD python3 pw.py

描述错误

剧作家启动 webkit 超时

docker build -t test-pw . && docker run test-pw
Traceback (most recent call last):
  File "//pw.py", line 11, in <module>
    asyncio.run(run())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "//pw.py", line 8, in run
    await playwright.webkit.launch(headless=True)
  File "/usr/local/lib/python3.10/dist-packages/playwright/async_api/_generated.py", line 11399, in launch
    await self._impl_obj.launch(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 43, in send
    return await self._connection.wrap_api_call(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 370, in _
    return await result
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 78, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/webkit-1668/pw_run.sh --inspector-pipe --headless --no-startup-window
<launched> pid=440
============================================================

回答

1

感谢您的代码片段!我尝试重新编译,但它没有错误。 docker 容器构建并运行干净。

您可以包含调试日志吗:DEBUG="pw:browser" python3 pw.py?谢谢!另外,你的机器的主机架构是什么? Linux 也可以吗?

1

感谢您的快速回复!

DEBUG="pw:browser" python3 pw.py

2022-07-13T09:56:27.026Z pw:browser <launching> /root/.cache/ms-playwright/webkit-1668/pw_run.sh --inspector-pipe --headless --no-startup-window
2022-07-13T09:56:27.028Z pw:browser <launched> pid=440
2022-07-13T09:56:56.833Z pw:browser [pid=440] <gracefully close start>
2022-07-13T09:56:56.835Z pw:browser [pid=440] <kill>
2022-07-13T09:56:56.836Z pw:browser [pid=440] <will force kill>
2022-07-13T09:56:56.838Z pw:browser [pid=440] <process did exit: exitCode=null, signal=SIGKILL>
2022-07-13T09:56:56.838Z pw:browser [pid=440] starting temporary directories cleanup
2022-07-13T09:56:56.842Z pw:browser [pid=440] finished temporary directories cleanup
2022-07-13T09:56:56.843Z pw:browser [pid=440] <gracefully close end>
Traceback (most recent call last):
  File "//pw.py", line 11, in <module>
    asyncio.run(run())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "//pw.py", line 8, in run
    await playwright.webkit.launch(headless=True)
  File "/usr/local/lib/python3.10/dist-packages/playwright/async_api/_generated.py", line 11399, in launch
    await self._impl_obj.launch(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 43, in send
    return await self._connection.wrap_api_call(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 370, in _
    return await result
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 78, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/webkit-1668/pw_run.sh --inspector-pipe --headless --no-startup-window
<launched> pid=440
============================================================

主持人:

$ uname -a
Linux tux 5.15.0-10033-tuxedo microsoft/playwright-python#34~20.04.1tux2 SMP Wed Jun 15 14:23:33 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
0

您可以尝试一下官方图片,看看是否会出现同样的错误?mcr.microsoft.com/playwright:v1.23.1-focal

这将有助于缩小范围。有很多地方可能会出错,但仅根据这些日志我还不确定。还请包含docker info有关内核版本信息的输出。

/抄送@aslushnikov

7

使用官方图像作品:

FROM mcr.microsoft.com/playwright/python:v1.23.0-focal

ADD ./pw.py pw.py
CMD DEBUG="pw:browser" python3 pw.py
$ docker build -t test-pw . && docker run test-pw
2022-07-14T15:31:50.947Z pw:browser <launching> /ms-playwright/webkit-1668/pw_run.sh --inspector-pipe --headless --no-startup-window
2022-07-14T15:31:50.949Z pw:browser <launched> pid=449
2022-07-14T15:31:51.252Z pw:browser [pid=449] <gracefully close start>
2022-07-14T15:31:51.257Z pw:browser [pid=449] <process did exit: exitCode=0, signal=null>
2022-07-14T15:31:51.257Z pw:browser [pid=449] starting temporary directories cleanup
2022-07-14T15:31:51.261Z pw:browser [pid=449] finished temporary directories cleanup
2022-07-14T15:31:51.261Z pw:browser [pid=449] <gracefully close end>

码头工人信息:

$ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  compose: Docker Compose (Docker Inc., v2.6.0)

Server:
 Containers: 7
  Running: 6
  Paused: 0
  Stopped: 1
 Images: 8
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux nvidia runc
 Default Runtime: nvidia
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.15.0-10041-tuxedo
 Operating System: Ubuntu 20.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.16GiB
 Name: **
 ID: **
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
5

它无法在 Mac 版 Docker 上重现,但我可以在 GitHub Codespaces 中的 Docker 上重现它。

  pw:browser <launching> /root/.cache/ms-playwright/webkit-1668/pw_run.sh --inspector-pipe --headless --no-startup-window +0ms
  pw:browser <launched> pid=440 +2ms
  pw:protocol SEND ► {"id":1,"method":"Playwright.enable"} +0ms
  pw:browser [pid=440] <gracefully close start> +30s
  pw:browser [pid=440] <kill> +1ms
  pw:browser [pid=440] <will force kill> +1ms
  pw:browser [pid=440] <process did exit: exitCode=null, signal=SIGKILL> +0ms
  pw:browser [pid=440] starting temporary directories cleanup +1ms
  pw:error Error: read ECONNRESET
  pw:error     at Pipe.onStreamRead (node:internal/stream_base_commons:220:20) +0ms
  pw:browser [pid=440] finished temporary directories cleanup +4ms
  pw:browser [pid=440] <gracefully close end> +0ms
Traceback (most recent call last):
  File "//pw.py", line 10, in <module>
    asyncio.run(run())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "//pw.py", line 7, in run
    await playwright.webkit.launch(headless=True)
  File "/usr/local/lib/python3.10/dist-packages/playwright/async_api/_generated.py", line 11399, in launch
    await self._impl_obj.launch(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 43, in send
    return await self._connection.wrap_api_call(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 370, in _
    return await result
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 78, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/webkit-1668/pw_run.sh --inspector-pipe --headless --no-startup-window
<launched> pid=440
============================================================
5

@aslushnikov 你能看一下吗?

tl;dr:snakepacker/python:3.10基于 ubuntu。snakepacker/python:3.10适用于 Docker-for-Mac,但不适用于 Docker for Linux(对于用户和我们在 GitHub Codespaces 中)。官方图片适用于所有这些地方。

2

根据 @aslushnikov 的请求转移到主仓库。这似乎是一个非 Python 特定的问题,更多的是与安装脚本有关。基础映像位于技术支持的操作系统上。

/cc @yury-s

8

@thebuchanan3 运行这个 docker 的主机操作系统是什么?您是否在主机和 Ubuntu 20.04 Focal 容器上运行 Ubuntu 18 Bionic 之类的东西?

9

@thebuchanan3 运行这个 docker 的主机操作系统是什么?您是否在主机和 Ubuntu 20.04 Focal 容器上运行 Ubuntu 18 Bionic 之类的东西?

我在焦点主机上运行了一个 jammy 容器

1

@thebuchanan3 所以有 2 个解决方法:

  • 使用Ubuntu 22运行Ubuntu 22(jammy)容器,即可运行。
  • 运行带--privileged标志的容器

这是由于 docker 架构和内核重用造成的:看起来 Jammy 的 WebKit 正在使用焦点内核在非特权模式下无法提供的东西。

2

我可以确认,如果您在运行 Ubuntu 20.04 的主机上基于 Ubuntu 22.04 的 docker 容器(来宾)中启动 WebKit,它会冻结。它在主机 Ubuntu 22.04 上运行的来宾 Ubuntu 22.04 上运行良好。我没有尝试解决方法--privileged(是不是有点危险?)。我继续使用基于 Ubuntu 20.04 的 docker 映像,因为我需要在不同的主机发行版(Ubuntu 20.04 和 22.04)上运行它。

3

因此,这是一个特定于 docker 的问题,而不是特定于 WebKit 的问题:容器仅抽象用户名称空间,而内核与主机共享。请参阅https://stackoverflow.com/questions/32841982/how-can-docker-run-distros-with- Different- kernels/56606244#56606244

看起来 Ubuntu 22 的 Webkit 需要一些来自 Ubuntu 22.04 内核的系统调用,而这些系统调用在 Ubuntu 20.04 的内核中不可用,因此出现了这个错误。

我现在将关闭它,因为这里没有剧作家团队的行动项目。

如果您认为我们仍然可以提供帮助,请提交新问题!

6

我仔细研究了一下,问题是 WebKit 的以下子进程挂起:

/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner -l /ms-playwright/webkit-1808/minibrowser-wpe/bin/MiniBrowser

可能是由于https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/937

要解决此问题,您可以ln -s /usr/bin/echo /usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner在 Docker 容器内进行。

您还可以尝试在 Docker 主机上升级 glib,因为它似乎已经在 glib 中修复了。

2

注意:我可以确认这将作为 1.34 的一部分得到修复。