完全headlessのリモートサーバーに仮想デスクトップを立ててchromedriverを動かしている環境で、ある日いきなりchromeが起動しなくなった。
症状
具体的には driver = webdriver.Remote()
がいつまで立っても終わらない。
VNCでつないでみるとタブの読み込み中アイコンがくるくる回り続けていて中止ボタンでも反応しない。そのまま手動で開いたタブは問題なく動く。
同じchromeでもheadlessモードで起動させたり、似た環境のデスクトップUbuntuで同じバージョンのchromedriverと同じソースコードの組み合わせでも再現しない。
解決策
起動オプションに --disable-gpu
を足す。pythonならこんな具合。
from selenium import webdriver
options = webdriver.chrome.options.Options()
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
chromedriver_url = "http://localhost:9515"
# selenium 3.4.x なら
driver = webdriver.Remote(chromedriver_url, options.to_capabilities())
# selenium 4.x なら
driver = webdriver.Remote(chromedriver_url, options=options)
共有メモリのせいで起動後即クラッシュする問題の回避に --disable-dev-shm-usage
、vmで起動しない問題の回避に --sandbox
。
普段はこれにウェブフォントを無効にして読み込み速度を上げる --disable-remote-fonts
、UserAgent指定、プロファイル指定やらなんやらつけている。
chromeのおまじないがまた増えてしまった。
環境
- Ubuntu Server 21.10
- Xvfb
- chromium 96.0.4664.45 via snap
- GPUなし
おそらくchromium 96に上がったタイミング。
詳細
chromedriver --verbose
でデバッグログを出して正常なものと見比べると
[DEBUG]: DevTools WebSocket Response: Page.addScriptToEvaluateOnNewDocument
[DEBUG]: DevTools WebSocket Response: DOM.getDocument
この2行目にたどり着いていない。代わりに
ERROR:gl_surface_egl.cc(734)] No suitable EGL configs found.
ERROR:gl_context_egl.cc(286)] eglCreateContext failed with error EGL_BAD_CONFIG
x() failed with unknown libva error, driver_name = (null)
ERROR:gl_surface_egl.cc(734)] No suitable EGL configs found.
ERROR:gl_surface_egl.cc(2172)] eglCreatePbufferSurface failed with error EGL_BAD_CONFIG
ERROR:gpu_info_collector.cc(77)] gl::GLContext::CreateOffscreenGLSurface failed
ERROR:gpu_info_collector.cc(378)] Could not create surface for info collection.
ERROR:gpu_init.cc(82)] CollectGraphicsInfo failed.
ERROR:viz_main_impl.cc(161)] Exiting GPU process due to errors during initialization
ERROR:angle_platform_impl.cc(44)] Display.cpp:894 (initialize): ANGLE Display::initialize error 0: Internal Vulkan error (-3): Initialization of an object could not be completed for implementation-specific reasons, in ../../third_party/angle/src/libANGLE/renderer/vulkan/RendererVk.cpp, initialize:1048.
ERROR:gl_surface_egl.cc(782)] EGL Driver message (Critical) eglInitialize: Internal Vulkan error (-3): Initialization of an object could not be completed for implementation-specific reasons, in ../../third_party/angle/src/libANGLE/renderer/vulkan/RendererVk.cpp, initialize:1048.
ERROR:gl_surface_egl.cc(1382)] eglInitialize SwANGLE failed with error EGL_NOT_INITIALIZED
ERROR:gl_ozone_egl.cc(20)] GLSurfaceEGL::InitializeOneOff failed.
ERROR:viz_main_impl.cc(161)] Exiting GPU process due to errors during initialization
邪魔なタイムスタンプを切っているのでブラケットが一致してないが、太字の箇所でGPUが原因の問題が起きていることがわかった。あとはそれらしいオプションを探して指定すれば解決。
参考リンク
- List of Chromium Command Line Switches « Peter Beverloo - chromeの起動オプション一覧。
--help
では出てこないので重宝する。