Closed
Description
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.
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
Labels
No labels