Skip to content

fix(sync): wait for initialize before leaving __enter__ - #3168

Open
Skn0tt wants to merge 2 commits into
microsoft:mainfrom
Skn0tt:skn0tt-fix-3165-sync-enter-init
Open

fix(sync): wait for initialize before leaving __enter__#3168
Skn0tt wants to merge 2 commits into
microsoft:mainfrom
Skn0tt:skn0tt-fix-3165-sync-enter-init

Conversation

@Skn0tt

Copy link
Copy Markdown
Member

Fixes half of #3165

sync_api/_context_manager.py blocked until the Playwright __create__, but
since #836 we really have to block until initialize finishes. Empty
with sync_playwright() was racing teardown against that still-in-flight RPC
and printing Future exception was never retrieved / Task was destroyed but it is pending on exit.

Migrating to wait on playwright_future (like async) also lets us drop the
now-unused call_on_object_with_known_name path.

Does not touch the separate JSON-serialization / register-after-send half.

Skn0ttand others added 2 commits August 4, 2026 17:09
Fixes: microsoft#3165
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 16cb16dc-1986-42c7-90ce-9549b32cfccb
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 16cb16dc-1986-42c7-90ce-9549b32cfccb
@Skn0tt
Skn0tt requested a review from dcroussoAugust 4, 2026 16:14
try:
self.playwright_future.set_result(await self._root_object.initialize())
except BaseException as exc:
self.playwright_future.set_exception(exc)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the async context manager cancels playwright_future when the transport fails first so this may raise InvalidStateError and replace the original failure in _init_task

self.playwright_future.set_result(await self._root_object.initialize())
except BaseException as exc:
self.playwright_future.set_exception(exc)
raise

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_init_task does not appear to be awaited or inspected so i think rethrowing here will emit Task exception was never retrieved after the caller has already received the startup error

Sign up for freeto 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.

2 participants

@Skn0tt@dcrousso