gramaziokohler / roslibpy

Python ROS Bridge library
MIT License
273 stars 56 forks source link

Sometimes stuck on is_connecting=True when switching wifi networks + Solution #97

Open SeeingFarther opened 2 years ago

SeeingFarther commented 2 years ago

Description When switching WiFi networks from the WiFi network with the ros bridge to a different WiFi network and then returning to the WiFi network with the ros bridge, will result sometimes with ros object stuck on is_connecting=True when trying to reconnect the ros bridge, even if the ros connection was closed properly.

More details 1.Trying to do initiate close() function of the ros object and then connect() function didn't helped in solving the problem.

  1. When looking closer at the problem I noticed the connector state of the RosBridgeClientFactory object is also stuck on 'connecting' tried closing and opening the factory connector.
  2. Switching between WiFi networks again didn't solved the problem.
  3. The ros bridge connection was closed properly every time.

Source of the problem When investigating the reason for this problem, I noticed it happens as a result of the mainloop function in /twisted/internet/base.py calls self.doIteration function with t=None, this function call result with the epollreactor object running the doPoll function with timeout=None, which means he waits indefinitely.

Solution I found I have created a timer which checks if we are in state of is_connecting=True for to long, if that's the case I run the following command:

< ros object >.factory.emit('close', < ros object >.factory._proto)

I wont get to details why it solves the problem.

To Reproduce

  1. Connect to the ros bridge.
  2. Wait until the doIteration function in the mainloop function has been called with None.
  3. Switch to a different WiFi network.
  4. Switch back to the WiFi network and try to reconnect the ros bridge.

System: