Skip to content

[internal] hang bug in PlaywrightContextManager and Transport #650

@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
    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