ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ros::service::waitForService() blocks infinite

asked 2013-03-18 08:57:45 -0600

inflo gravatar image

updated 2021-10-26 13:35:16 -0600

lucasw gravatar image

When i use ros::service::call() to call e.g. gazebo/apply_joint_effort inside a rostest (c++,gtest) the call sometimes fail and sometimes don't fail ?

So i thought, using ros::service::waitForService("gazebo/apply_joint_effort", -1)) to wait for "something" and then use the call() function, but the waitForService() is blocking endless. But when i call the service with the commandline tool "rosservice", the service is available and returns success ?

is waitForService() for another usage?

thanks flo

Change 1: Inserting

rosbuild_add_gtest(test/mytest test/mytest.cpp)

into CMakeList.txt file and running then the binary bin/test/mytest the service call returns success, but the service (force) does not get applied to the model in gazebo?

gazebo dies with:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Time is out of dual 32-bit range

Aborted (core dumped)

I got ubuntu-12.04-amd64 installed. Someone knows what this error causes?

Also if i use:


in my CMakeList.txt file instead the two other options mentioned before, and run rostest mypackage mytest the test is run 3 times in a row after building? Why is that so? Also the rostest lib cannot call the service, but the test-binary can call the service (but gazebo dies) ?

Is there a way to prevent the test from running after building it with make test?

edit retag flag offensive close merge delete


the call ros::service::waitForService("/gazebo/apply_joint_effort", -1) blocks also infinite ?

my test is just:

TEST(MyTest, firstTest) { ros::Time::init(); //used for waitForService if(ros::service::waitForService("/gazebo/apply_joint_effort", -1)) EXPECT_EQ(1,2) << "wait for service ok"; }

Are there some other functions i can call to get more info? like what namespace i am in, or something?

thanks flo

inflo gravatar image inflo  ( 2013-03-19 05:56:43 -0600 )edit

Please do not create answers for discussion or comments. Instead, either edit and append to your original post or use the comment functionality.

dornhege gravatar image dornhege  ( 2013-03-19 06:55:30 -0600 )edit

I think running it is the intended behaviour of make test.

dornhege gravatar image dornhege  ( 2013-03-20 06:09:30 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-03-18 11:26:10 -0600

dornhege gravatar image

You are passing -1 for the timeout, which means: wait infinite. Just pass a real timeout that you want to wait for.

edit flag offensive delete link more


yes i pass -1 because i want to block so long till i get the service. I know that the service is available because i can run rosservice from console "before" and "after" i run the rostest with the awaitForService() call. The question is more: why is it blocking, but the service is available ?

inflo gravatar image inflo  ( 2013-03-18 21:43:17 -0600 )edit

Maybe you did something wrong in the software. You can just call the service to see, if it works in principle.

dornhege gravatar image dornhege  ( 2013-03-19 01:28:35 -0600 )edit

like i wrote in my question, it sometimes works and sometimes fails

inflo gravatar image inflo  ( 2013-03-19 03:25:14 -0600 )edit

How are you registering the service client/calling the service? Also ros::service::call?

dornhege gravatar image dornhege  ( 2013-03-19 05:58:06 -0600 )edit

what does the <2> and the green check-mark right beside your answer mean ?

inflo gravatar image inflo  ( 2013-03-19 05:59:21 -0600 )edit

yes i use (ros::service::call("/gazebo/apply_joint_effort", req, res)

inflo gravatar image inflo  ( 2013-03-19 06:00:00 -0600 )edit

Your call does have a / before gazebo unlike the waitForService. Did you try @Hansg91's suggestion?

dornhege gravatar image dornhege  ( 2013-03-19 06:02:45 -0600 )edit

yes i tried it, like i wrote in the answer to Hansg91 :)

inflo gravatar image inflo  ( 2013-03-19 06:05:15 -0600 )edit

answered 2013-03-19 02:06:33 -0600

Hansg91 gravatar image

I'm not sure but it might be using your namespace in the check if it is available (and is therefore waiting for /your_ns/gazebo/apply_joint_effort).

Could you try :

ros::service::waitForService("/gazebo/apply_joint_effort", -1));

That might work, because it is then ignoring your namespace. At least for registering and subscribing topics this is the case.

edit flag offensive delete link more


with the namespaces i must check (later), but i need the service to publish a service request, so registering and subscribing is not enough. i reply if it works

inflo gravatar image inflo  ( 2013-03-19 03:27:12 -0600 )edit

There are some functions for that in the ros namespace. However, if you use the / this shouldn't matter unless you remapped that.

dornhege gravatar image dornhege  ( 2013-03-19 06:55:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-18 08:57:45 -0600

Seen: 7,262 times

Last updated: Oct 26 '21