roslibpy icon indicating copy to clipboard operation
roslibpy copied to clipboard

connect() doesn't work

Open xibei312 opened this issue 1 year ago • 9 comments

Description connect() doesn't reconnect

To Reproduce Steps to reproduce the behavior: ros.close() // Connection is closed // Wait for ~2 seconds ros.connect() // Reconnected to websocket

Expected behavior ros.close() // Connection is closed // Wait for ~2 seconds ros.connect() // Doesn't reconnect ros.is_connected outputs False

Reproduction Steps import roslibpy import time ros = roslibpy.Ros(host, port) ros.run() ros.close() time.sleep(5) ros.connect()

System (please complete the following information):

  • OS: [ubuntu20.04]
  • Python version [3.8]
  • Python package manager [pip]
  • roslibpy version[1.3.0]

Additional context

xibei312 avatar Jul 11 '22 09:07 xibei312

I have the same problem

dkarakay avatar Aug 19 '22 13:08 dkarakay

Are you going to publish a new update? @gonzalocasas

dkarakay avatar Aug 22 '22 12:08 dkarakay

@dkarakay I cannot reproduce the problem. I just executed the following script on the python interpreter, which is basically the exact same as the "Reproduction steps" posted by @xibei312, but it reconnects correctly as far as I can see:

image

Also rosbridge reports correctly the connection/disconnection: image

I think the only problem is that you are not waiting enough time to check if it's really re-connected, because if I add a few time.sleep statements in the reproduction steps and run as script, it also behaves correctly:

image

@dkarakay @xibei312 do you agree with this? is it ok to close the issue?

gonzalocasas avatar Aug 23 '22 07:08 gonzalocasas

No, most of the time waiting is enough, but at some point, the client enters a loop in which it stucks in the connecting process and cannot not establish the connection in the end. It has mostly happened when we have multiple clients etc. What I mean is that the system is not stable.

dkarakay avatar Aug 23 '22 07:08 dkarakay

@dkarakay would you be able to provide a script that reproduces this behavior?

Because I haven't really seen that unstable behavior so far. Not on the autobahn-based implementation of the connection at least (I did noticed some issues on the .net implementation of reconnections). If I understand correctly, you are running this from CPython (not Ironpython), so you should be using the autobahn part.

gonzalocasas avatar Aug 23 '22 07:08 gonzalocasas

Actually, our system is based on Autobahn. I will reproduce it and share the logs with you. Thank you for your help

dkarakay avatar Aug 24 '22 08:08 dkarakay

I'm not good at English, so I'm writing with a translator. I'm having the same situation as dkarakay. image Always get False for the above code. image This is the code I tested. The result of my test is that it seems to work well if I connect quickly (within 1 second) after closing, but I have confirmed that it does not work well if I give a delay of more than 5 seconds. I want to solve this problem

OS : CentOS 7.9 Python version : 3.8.16 roslibpy version : 1.3.0

withme8011 avatar Feb 03 '23 09:02 withme8011

I share my test results. It was confirmed that the test code of gonzalocasas works perfectly on Windows 10. I think the OS or python version is the problem, so I tested it alternately on Windows 10/CentOS7.9 / Ubuntu22.04, python 3.8.16 / 3.10.2, and it was confirmed that it works abnormally only in Linux. At this time, SYN did not appear in wireshark. I think there might be a problem with the scheduling of the function that connects after close internally. Because the SYN doesn't show up in wireshark, it actually indicates that the connect function isn't being called. If I have any additional confirmed results, I will share them.

withme8011 avatar Feb 08 '23 07:02 withme8011

Hi, I had a similar problem in Linux (Ubuntu 20.04), where connecting a 2nd time failed on Linux but worked on Windows 10. However, to reconnect after closing, I use the .run() method again instead of the .connect() method. I found that on Windows on the 1st time it connects immediately, and on the 2nd time it takes like ~1-2 seocnds. I realized that there are some clean up remains on the 2nd time that take some time, and it is longer on Linux. I increased my .run timeout from 1 second to 5 seconds (the default is 10 seconds) and it worked (takes some seconds).

Here is the basic code (I use .close and shortly later .run again): ` def run(self, timeout=5):

if self._is_started:
    return

with self.lock:

    self._is_started = True
    self._ros = roslibpy.Ros(host=self.host, port=self.port, is_secure=self.is_secure)

    try:
        self._ros.run(timeout=timeout)
        self._print_msg("Started.")

    except roslibpy.core.RosTimeoutError:
        self._is_started = False
        self._print_msg("Connection Failed.")

def close(self):

with self.lock:

    if self._is_started:

        self._ros.close()

    self._ros = None

    self._is_started = False

`

ido-rachbuch avatar Jun 06 '24 08:06 ido-rachbuch