Skip to content

[internal] hang bug in PlaywrightContextManager and Transport #650

Closed
@x0day

Description

@x0day

with recently feature(pull/630), playwright-python can connect to remote websocket endpoint, but with this feature, a bug become obvious.

playwright-python doesn't handle the transport's connection error during the connecting, if error found during the connecting. the task will be hang, because below code will never return.

https://github.com/microsoft/playwright-python/blob/master/playwright/async_api/_context_manager.py#L37

self._connection.wait_for_object_with_known_name("Playwright")

eg:

Connect call failed in WebSocketTransport.

maybe we should wait the obj and Transport.on_error_future same time in PlaywrightContextManager like this:

class WebSocketTransport(AsyncIOEventEmitter, Transport):
    ...
    async def run(self) -> None:
        ...

        try:
            self._connection = await websockets.connect(self.ws_endpoint, **options)
        except Exception as exc:
            self.emit("close")
            self.on_error_future.set_exception(exc)
       ...
class PlaywrightContextManager:
    ...
    async def __aenter__(self) -> AsyncPlaywright:
        ...
        done, pending = await asyncio.wait(
            {
                self._connection._transport.on_error_future,
                self._connection.wait_for_object_with_known_name("Playwright"),
            },
            return_when=asyncio.FIRST_COMPLETED,
        )
        obj = next(iter(done)).result()
        playwright = AsyncPlaywright(obj)
        ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy