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)
...
with recently feature(pull/630), playwright-python can connect to remote websocket endpoint, but with this feature, a bug become obvious.
playwright-pythondoesn'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
eg:
Connect call failedinWebSocketTransport.maybe we should wait the
objandTransport.on_error_futuresame time inPlaywrightContextManagerlike this: