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

rosnode: Explicitly handle socket.timeout in rosnode ping #1517

Merged

Conversation

msadowski
Copy link
Contributor

This pull request is in response to #1516. There are some cases where rosnode ping would take over 30 seconds to scan all the nodes due to ValueError happening when trying to unpack socket.error.

This pull request adds handling of socket.timeout explicitly.

Please let me know if there is anything else you would like me to change.

@msadowski msadowski changed the title Explicitly handle socket.timeout in rosnode ping rosnode: Explicitly handle socket.timeout in rosnode ping Oct 4, 2018
@@ -336,6 +336,9 @@ def rosnode_ping(node_name, max_count=None, verbose=False):
if verbose:
print("xmlrpc reply from %s\ttime=%fms"%(node_api, dur))
# 1s between pings
except socket.timeout:
print("connection to [%s] timed out"%node_name, file=sys.stderr)
return False
Copy link
Member

Choose a reason for hiding this comment

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

With this extra block added can line 364 still happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into documentation of socket I believe it should not happen when we handle timeout error explicitly.

Socket has 4 exceptions:

  • socket.error - can return either a string or (errno, string)
  • socket.herror - (h_errno, string)
  • socket.gaierror - (error, string)
  • socket.timeout - string

since the timeout is the only subclass of socket.error that returns a single string I think the line 364 should never happen (unless I'm missing anything else that could raise a ValueError that is not related to unpacking the error).

Would you like me to remove this ValueError check?

Copy link
Member

Choose a reason for hiding this comment

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

since the timeout is the only subclass of socket.error that returns a single string I think the line 364 should never happen

The the following message should be changed to state that something "unknown" has happened, e.g.:

                     else:
                         print("connection to [%s] timed out"%node_name, file=sys.stderr)

replaced by:

                     else:
                         print("connection to [%s] failed"%node_name, file=sys.stderr)

Would you like me to remove this ValueError check?

I would rather keep that - there is no reason related to the issue here (the timeout) that it should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarification. I just pushed the change.

@dirk-thomas
Copy link
Member

Thanks for the patch.

@dirk-thomas dirk-thomas merged commit b5ee2db into ros:melodic-devel Oct 8, 2018
tahsinkose pushed a commit to tahsinkose/ros_comm that referenced this pull request Apr 15, 2019
* Explicitly handle socket.timeout in rosnode ping

* Change error string when handling socket.error
dirk-thomas pushed a commit that referenced this pull request Aug 3, 2020
* Explicitly handle socket.timeout in rosnode ping

* Change error string when handling socket.error
dirk-thomas pushed a commit that referenced this pull request Aug 3, 2020
* Explicitly handle socket.timeout in rosnode ping

* Change error string when handling socket.error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants