Skip to content

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

Description

@rahulrao85

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions