microsoft / microsoft/Webwright

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

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
6k
Forks
384
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in local_browser.py at _is_local_cdp_available(), _local_cdp_page_targets(), _ensure_local_cdp_page_target(), and _ensure_local_cdp_browser(); inspect how these helpers are called and review the existing httpx dependency in pyproject.toml. Replace blocking HTTP and sleep operations with async equivalents, then verify CDP startup does not block or prevent cancellation of the polling loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.