Skip to content

fix(transport): handle connection error correctly (#650) #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 4, 2021
Prev Previous commit
Next Next commit
fix: cancel the obj when error
  • Loading branch information
dm committed Apr 27, 2021
commit 99289bfaac978fc9fddc2138744db77c411d5c61
15 changes: 14 additions & 1 deletion playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
from pathlib import Path
from typing import Dict, List, Optional, Union, cast

Expand Down Expand Up @@ -174,8 +175,20 @@ async def connect(
connection._is_sync = self._connection._is_sync
connection._loop = self._connection._loop
connection._loop.create_task(connection.run())
obj = asyncio.ensure_future(
connection.wait_for_object_with_known_name("Playwright")
)
done, pending = await asyncio.wait(
{
obj,
connection._transport.on_error_future, # type: ignore
},
return_when=asyncio.FIRST_COMPLETED,
)
if not obj.done():
obj.cancel()
playwright = next(iter(done)).result()
self._connection._child_ws_connections.append(connection)
playwright = await connection.wait_for_object_with_known_name("Playwright")
pre_launched_browser = playwright._initializer.get("preLaunchedBrowser")
assert pre_launched_browser
browser = cast(Browser, from_channel(pre_launched_browser))
Expand Down