Fixed uninitialized Time usage in rosservice call #2369
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When launching my application with sim time, I sometimes get a fail from a
rosservice call --wait /node/set_logger_level ...
which is launched from the launch file together with the node it is configuring. The fail is not easily reproducible in a simple MWE. In my application, it happens in ~20% launches.The error I get is:
The explanation is simple: In case
contact_service()
ends withConnection refused
(this is the hard-to-reproduce part, but it happens on node startup), it calls:ros_comm/clients/rospy/src/rospy/impl/tcpros_service.py
Line 163 in 845f746
However, for the throttle to work, ROS time has to be initialized. However, rosservice does
init_node()
only later in the code, so at time of the throttled logging, ROS time is not yet initialized.This fix uses the same approach as rostopic: explicitly initialize time prior to any possible logging:
ros_comm/tools/rostopic/src/rostopic/__init__.py
Lines 1013 to 1014 in 845f746
I tried to write an MWE, but I could not reproduce it with it. Probably, the called node has to have a bit more complicated startup...
With this fix, I can see the throttled message being correctly written to the terminal in the 20% failing cases, and the
rosservice call
finishes successfully in thecontact_service()
call.