diff --git a/cylc/flow/hostuserutil.py b/cylc/flow/hostuserutil.py index 34e033b2d7b..2f2b2b234d6 100644 --- a/cylc/flow/hostuserutil.py +++ b/cylc/flow/hostuserutil.py @@ -113,24 +113,28 @@ def get_host_ip_by_name(target): """Return internal IP address of target.""" return socket.gethostbyname(target) + @staticmethod + def resolve_macos_ip6_fqdn(target: str) -> str: + """Python's socket bindings don't play nicely with MacOS + so we sometimes get an ip6.arpa address from + socket.getfqdn. + + Note that this does *not* match `hostname -f`. + https://github.com/cylc/cylc-flow/issues/2689 + https://github.com/cylc/cylc-flow/issues/3768 + """ + if IS_MAC_OS and target == ( + '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.' + '0.0.0.0.0.0.ip6.arpa' + ): + return socket.gethostname() + return target + def _get_host_info(self, target=None): """Return the extended info of the current host.""" if target not in self._host_exs: if target is None: - target = socket.getfqdn() - if ( - IS_MAC_OS - and target == ( - '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.' - '0.0.0.0.0.0.ip6.arpa' - ) - ): - # Python's socket bindings don't play nicely with mac os - # so by default we get the above ip6.arpa address from - # socket.getfqdn, note this does *not* match `hostname -f`. - # https://github.com/cylc/cylc-flow/issues/2689 - # https://github.com/cylc/cylc-flow/issues/3595 - target = socket.gethostname() + target = self.resolve_macos_ip6_fqdn(socket.getfqdn()) try: self._host_exs[target] = socket.gethostbyname_ex(target) except IOError as exc: @@ -202,12 +206,15 @@ def is_remote_host(self, name): self._remote_hosts[name] = False else: try: - host_info = self._get_host_info(name) + ip_addr = socket.gethostbyname(name) except IOError: self._remote_hosts[name] = True else: self._remote_hosts[name] = ( - host_info != self._get_host_info()) + ip_addr != socket.gethostbyname( + self.resolve_macos_ip6_fqdn(socket.getfqdn()) + ) + ) return self._remote_hosts[name] def is_remote_user(self, name):