Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout fundamentals for daemon client communication #886

Draft
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions ros2cli/ros2cli/node/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
from ros2cli.helpers import wait_for

from ros2cli.xmlrpc.client import ServerProxy
from ros2cli.xmlrpc.client import TimeoutTransport


class DaemonNode:

def __init__(self, args):
def __init__(self, args, *, timeout=None):
self._args = args
self._proxy = ServerProxy(
daemon.get_xmlrpc_server_url(),
allow_none=True)
allow_none=True,
transport=TimeoutTransport(timeout=timeout))
self._methods = []

@property
Expand Down Expand Up @@ -65,13 +67,16 @@ def __exit__(self, exc_type, exc_value, traceback):
self._proxy.__exit__(exc_type, exc_value, traceback)


def is_daemon_running(args):
def is_daemon_running(args, timeout=None):
"""
Check if the daemon node is running.

:param args: `DaemonNode` arguments namespace.
:param timeout: option duration, in seconds, to wait
for the daemon node to respond. If it is not given,
the global default timeout setting is used.
Comment on lines +76 to +77
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using global default timeout would never time out with my environment... trying to access the server to list the method in localhost, it is not expected to take more than 10 seconds, maybe we can set specific timeout in default here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of any reasonable circumstances where it would take longer than that either. I'm in favor of a default timeout as well, but I think we need more feedback on what value might be appropriate.

I also think we need to improve the error message if it becomes the default behavior. Right now, the exception is unhandled.

"""
with DaemonNode(args) as node:
with DaemonNode(args, timeout=timeout) as node:
return node.connected


Expand Down
17 changes: 16 additions & 1 deletion ros2cli/ros2cli/xmlrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@
# Alias xmlrpc.client module objects to ensure client code uses ros2cli.xmlrpc
from xmlrpc.client import ProtocolError
from xmlrpc.client import ServerProxy
from xmlrpc.client import Transport


__all__ = [
'ProtocolError',
'ServerProxy'
'ServerProxy',
'TimeoutTransport',
]


class TimeoutTransport(Transport):

def __init__(self, *args, timeout=None, **kwargs):
super().__init__(*args, **kwargs)
self._timeout = timeout

def make_connection(self, *args, **kwargs):
connection = super().make_connection(*args, **kwargs)
if self._timeout is not None:
connection.timeout = self._timeout
return connection
4 changes: 2 additions & 2 deletions ros2cli/test/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

@pytest.fixture
def enforce_no_daemon_is_running():
if is_daemon_running(args=[]):
if is_daemon_running(args=[], timeout=5.0):
assert shutdown_daemon(args=[], timeout=5.0)
yield


@pytest.fixture
def enforce_daemon_is_running():
if not is_daemon_running(args=[]):
if not is_daemon_running(args=[], timeout=5.0):
assert spawn_daemon(args=[], timeout=5.0)
yield

Expand Down