From b32e5025972795eecb36b30a23c4939da5d92397 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 1 Aug 2022 22:25:39 -0500 Subject: [PATCH] connect: Correctly handle IPv4 addresses It seems that the "shortcut" of using the `AF_INET6` address family for both IPv4 and IPv6 address does not always work. As such, we have to determine the correct family for the address by calling `getaddrinfo`. --- src/aiomarionette/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/aiomarionette/__init__.py b/src/aiomarionette/__init__.py index 6c26c90..606f328 100644 --- a/src/aiomarionette/__init__.py +++ b/src/aiomarionette/__init__.py @@ -255,11 +255,21 @@ class Marionette(WebDriverBase): self.port, ) try: + res = await loop.getaddrinfo( + self.host, self.port, type=socket.SOCK_STREAM + ) + if res: + family = res[0][0] + host, port = res[0][4][:2] + else: + host = self.host + port = self.port + family = socket.AF_INET transport, _protocol = await loop.create_connection( lambda: _MarionetteProtocol(self), - host=self.host, - port=self.port, - family=socket.AF_INET6, + host=host, + port=port, + family=family, ) fut = self._waiting[-1] = loop.create_future() hello: Dict[str, Any] = await fut