Skip to content

Commit

Permalink
Fix route problem when both service listening 0.0.0.0:port calling ea…
Browse files Browse the repository at this point in the history
…ch other

Two service listen on 0.0.0.0:1234, on different hosts:

xoscar.actor_ref(111.111.111.111:1234) will return unexpected LocalActorRef.

log print in context.actor_ref(111.111.111.111:1234)

    actor_ref ActorRef(uid=b'supervisor', address='111.111.111.111:1234')
    _call 111.111.111.111:1234
    get client 111.111.111.111:1234
    got LocalActorRef(uid=None, address='0.0.0.0:1234'), actor_weakref=<weakref at 0x75745bcdecf0; to 'CloudSupervisorActor' at 0x75745d3ed260>
    fix_all_zero_ip()
    got LocalActorRef(uid=None, address='111.111.111.111:1234'), actor_weakref=<weakref at 0x75745bcdecf0; to 'CloudSupervisorActor' at 0x75745d3ed260>

using the returned LocalActorRef, method call intend 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.
  • Loading branch information
frostyplanet committed Aug 18, 2024
1 parent 3c5a6a3 commit 18a20ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/xoscar/backends/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -164,7 +164,11 @@ 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,
# avoid mistaken with another service listen on non-zero ip with the same port,
# which might cause loop
register_local_pool(external_address, self)
self.process_index = process_index
self.label = label
self.external_address = external_address
Expand Down
4 changes: 4 additions & 0 deletions python/xoscar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18a20ca

Please sign in to comment.