From bb150cd531ded713bd55a1d47a230c03c7e099ce Mon Sep 17 00:00:00 2001 From: plan Date: Sun, 18 Aug 2024 13:05:15 +0800 Subject: [PATCH] Fix route problem when both service listening 0.0.0.0:port calling each other Two services on different hosts both listen on 0.0.0.0:port, xoscar.actor_ref(remote_addr:port) will return unexpected LocalActorRef. log print in context.actor_ref(address=remote_addr:port) actor_ref ActorRef(uid=b'supervisor', address='remote_addr:port') _call remote_addr:port get client remote_addr:port got LocalActorRef(uid=None, address='0.0.0.0:port'), actor_weakref= fix_all_zero_ip() got LocalActorRef(uid=None, address='remote_addr:port'), actor_weakref= using the returned LocalActorRef, method call intended for remote service actually sent to local service. The solution is simple, during pool initialization, do not register_local_pool if address is all zero. --- python/xoscar/backends/pool.py | 7 +++++-- python/xoscar/utils.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/python/xoscar/backends/pool.py b/python/xoscar/backends/pool.py index 6e3859d8..52cb664e 100644 --- a/python/xoscar/backends/pool.py +++ b/python/xoscar/backends/pool.py @@ -41,7 +41,7 @@ ServerClosed, ) from ..metrics import init_metrics -from ..utils import implements, register_asyncio_task_timeout_detector +from ..utils import implements, is_zero_ip, register_asyncio_task_timeout_detector from .allocate_strategy import AddressSpecified, allocated_type from .communication import ( Channel, @@ -164,7 +164,10 @@ def __init__( ): # register local pool for local actor lookup. # The pool is weakrefed, so we don't need to unregister it. - register_local_pool(external_address, self) + if not is_zero_ip(external_address): + # Only register_local_pool when we listen on non-zero ip (because all-zero ip is wildcard address), + # avoid mistaken with another remote service listen on non-zero ip with the same port. + register_local_pool(external_address, self) self.process_index = process_index self.label = label self.external_address = external_address diff --git a/python/xoscar/utils.py b/python/xoscar/utils.py index 643c065d..6c60f973 100644 --- a/python/xoscar/utils.py +++ b/python/xoscar/utils.py @@ -480,6 +480,10 @@ def is_v6_zero_ip(ip_port_addr: str) -> bool: return True +def is_zero_ip(ip_port_addr: str) -> bool: + return is_v4_zero_ip(ip_port_addr) or is_v6_zero_ip(ip_port_addr) + + def is_v6_ip(ip_port_addr: str) -> bool: arr = ip_port_addr.split("://", 1)[-1].split(":") return len(arr) > 1