Webwright icon indicating copy to clipboard operation
Webwright copied to clipboard

Blocking synchronous I/O (time.sleep, urllib) inside async event loop degrades performance

Open rahulrao85 opened this issue 4 months ago • 0 comments

Description

In \local_browser.py, several synchronous I/O operations run inside async methods, blocking the asyncio event loop:

  1. _is_local_cdp_available()\ (line 58) and _local_cdp_page_targets()\ (line 73) use \urllib.request\ synchronously
  2. _ensure_local_cdp_browser()\ (line 262) uses \ ime.sleep(0.2)\ in a polling loop, blocking the loop for up to 10 seconds
  3. _ensure_local_cdp_page_target()\ (line 93) uses synchronous urllib

\httpx\ is already listed as a dependency in \pyproject.toml\ (line 11) but isn't used anywhere.

Impact

  • The event loop is blocked during CDP browser startup for up to 10 seconds
  • \ ime.sleep()\ is not interruptible (unlike \syncio.sleep())
  • Concurrent operations on the same event loop cannot make progress
  • The polling loop cannot be cancelled mid-wait

Suggested Fix

Replace the synchronous helpers with async versions using \httpx.AsyncClient, convert _ensure_local_cdp_browser\ to async, and use \syncio.sleep()\ instead of \ ime.sleep().

The fix is straightforward since httpx is already a project dependency.

rahulrao85 avatar Jul 14 '26 04:07 rahulrao85