fix: replace blocking synchronous I/O with async httpx in CDP browser startup by rahulrao85 · Pull Request #61 · microsoft/Webwright · GitHub
Skip to content

fix: replace blocking synchronous I/O with async httpx in CDP browser startup - #61

Open
Rahul Rao (rahulrao85) wants to merge 1 commit into
microsoft:mainfrom
rahulrao85:fix-blocking-io-in-async
Open

fix: replace blocking synchronous I/O with async httpx in CDP browser startup#61
Rahul Rao (rahulrao85) wants to merge 1 commit into
microsoft:mainfrom
rahulrao85:fix-blocking-io-in-async

Conversation

@rahulrao85

Copy link
Copy Markdown

Summary

The CDP browser startup helpers used blocking \urllib.request\ and \ ime.sleep()\ inside async methods, blocking the asyncio event loop for up to 10 seconds. This is particularly problematic because the agent loop cannot make progress or be cancelled during CDP polling.

Changes

  • Added async versions of _is_local_cdp_available, _local_cdp_page_targets, and _ensure_local_cdp_page_target\ using \httpx.AsyncClient\ (httpx is already a project dependency)
  • Converted _ensure_local_cdp_browser\ to async with \�syncio.sleep()\ instead of \ ime.sleep()\
  • Updated _prepare_async\ to await the new async methods
  • Removed unused \urllib.request\ imports (\ProxyHandler, \Request, \�uild_opener)

Fixes: #56

… startup

The _is_local_cdp_available, _local_cdp_page_targets, and _ensure_local_cdp_page_target functions used blocking urllib.request and time.sleep() inside async methods, blocking the asyncio event loop for up to 10 seconds.

Changes:

- Replace synchronous urllib.request with httpx.AsyncClient (httpx is already a dependency)

- Replace time.sleep() with asyncio.sleep() in the CDP polling loop

- Convert _ensure_local_cdp_browser to async

- Remove unused urllib imports

Fixes: microsoft#56
@microsoft-github-policy-service

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant