Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions dimos/porcelain/remote_module_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import copyreg
import pickle
import threading
import time
from types import MappingProxyType
from typing import TYPE_CHECKING, Any

Expand All @@ -25,6 +26,8 @@
from dimos.porcelain.module_source import ModuleSource
from dimos.utils.logging_config import setup_logger

_CONNECT_RETRY_DEADLINE_S = 2.0

if TYPE_CHECKING:
from dimos.core.coordination.blueprints import Blueprint

Expand Down Expand Up @@ -53,7 +56,7 @@ class RemoteModuleSource(ModuleSource):
is_remote = True

def __init__(self, host: str, port: int) -> None:
self._coord_conn = rpyc.connect(host, port, config={"sync_request_timeout": 30})
self._coord_conn = _rpyc_connect(host, port, config={"sync_request_timeout": 30})
self._cache: dict[str, tuple[rpyc.Connection, Any]] = {}
self._lock = threading.RLock()

Expand All @@ -68,7 +71,7 @@ def get_rpyc_module(self, name: str) -> Any:

endpoint = self._coord_conn.root.get_module_endpoint(name)
host, port, module_id = endpoint[0], int(endpoint[1]), int(endpoint[2])
conn = rpyc.connect(host, port, config={"sync_request_timeout": 30})
conn = _rpyc_connect(host, port, config={"sync_request_timeout": 30})
module = conn.root.get_module(module_id)
self._cache[name] = (conn, module)
return module
Expand Down Expand Up @@ -105,3 +108,16 @@ def close(self) -> None:
self._coord_conn.close()
except Exception:
pass


def _rpyc_connect(host: str, port: int, **kwargs: Any) -> rpyc.Connection:
deadline = time.monotonic() + _CONNECT_RETRY_DEADLINE_S
delay = 0.010
while True:
try:
return rpyc.connect(host, port, **kwargs)
except ConnectionRefusedError:
if time.monotonic() >= deadline:
raise
time.sleep(delay)
delay = min(delay * 2, 0.200)
Loading