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

Yarpserver get stuck if it reads a string with a single " #1542

Open
traversaro opened this issue Feb 15, 2018 · 16 comments
Open

Yarpserver get stuck if it reads a string with a single " #1542

traversaro opened this issue Feb 15, 2018 · 16 comments
Assignees
Labels
Affects: YARP v2.3.72 This is a known issue affecting YARP v2.3.72 Component: GUI - yarpmanager Component: Library - YARP_os Component: Tool - yarpserver Issue Type: Bug Involves some intervention from a system administrator

Comments

@traversaro
Copy link
Member

At vvv18, one team had several different problems when a xml application file was malformed because it contained a " in the port name in the connection tag:

<connection>
  <from>"/module/port1</from> 
  <to>/module/port2</to>
  <protocol>tcp</protocol>
</connection>

or in dependencies tag:

<dependencies>
  <port>"/module/port1</port>
</dependencies>

The problems seems to be both at the yarpmanager level ( that was freezing ) @Nicogene and at the yarpserver level, that was behaving in a strange way when queryed with a port name like "/module/port1 @drdanz . A possible solution could be to sanitize port names loaded from the application file, as soon as possible.

cc @marco-monforte @atabakd @JuanMiguelAlvarez @ericpairet @anqingd @raedbsili1991 please provide any additional details that could be useful to avoid this problem in the future, thanks!

@traversaro traversaro changed the title Various problem created if a yarpmanager xml files contains a " Various problem created if a yarpmanager xml files contains a " in a port name Feb 15, 2018
@traversaro traversaro changed the title Various problem created if a yarpmanager xml files contains a " in a port name Various problem arise if a yarpmanager xml file contains a " in a port name Feb 15, 2018
@traversaro traversaro added Issue Type: Bug Involves some intervention from a system administrator Component: Tool - yarpserver Component: GUI - yarpmanager labels Feb 15, 2018
@Nicogene Nicogene self-assigned this Feb 16, 2018
@Nicogene
Copy link
Member

Somehow related to #1508. I think we should sanitize the port names in general 😅
Thanks for reporting, I will investigate why yarpmanager freeze !
The freeze happens when you try to connect the malformed port ??

@traversaro
Copy link
Member Author

traversaro commented Feb 16, 2018

I will let the students answer this, in particular @marco-monforte and @anqingd that work in the iCub Facility.

@ericpairet
Copy link

ericpairet commented Feb 16, 2018

Hi @traversaro @Nicogene. I had a look at the history of our cursed .xml file. Here goes the snippet:

<connection>
     <from>/orange/vision/controller:o</from>
     <to>"/orange/vision/controller:i"</to>
     <protocol>tcp</protocol>
</connection>

Unfortunately, we only saw one of the two " during our last time slot, and by then we run out of time to test it agian. That's why in the demo, yarpmanager freezed again, with only one ".

If I don't remember incorrectly, yarpmanager was freezing as soon as the modules in the app were run. I guess that this behaviour might be straightforward to reproduce at least, with the code in our repository. Apart from the " issue, there is the remote chance that something else was contributing to the freeze.

@marco-monforte
Copy link
Contributor

Hi guys and sorry for replying only now, but I traveled all the day yesterday.

Anyway, as @ericpairet said, the problem was the apexes in the port name. This should be easily repeatable from one of the last commits (or maybe even from the last, if Eric didn't change the error 😜). We can have a look together at IIT on Monday or as soon as you are available.

@Nicogene
Copy link
Member

My hope was that it was a yarpmanager problem, but I'm afraid that it is deeper 😔
yarpmanager before connecting checks that the ports exist calling NetworkBase::exists(...)
If you call:

yard::os::NetworkBase::exists("\"notExistingPort")

it get stuck.

So I would move this issue as a libYARP_OS issue, what do you think about @drdanz @traversaro ?

@Nicogene
Copy link
Member

Digging into the YARP core I found out that the problem is that the NameClient sends a query to the nameserver and waits that yarpserver answer back.
On the other side the yarpserver get stuck in yarp::name::NameServerConnectionHandler::read, in particular here:

        yarp::os::Bottle cmd, reply, event;
        bool ok = cmd.read(reader);

where reader is a ConnectionReader...

I think that the problem is in the parsing in BottleImpl::read() 🤔

@traversaro
Copy link
Member Author

traversaro commented Feb 20, 2018

Her daughter is named Help I'm trapped in a driver's license factory.

@Nicogene
Copy link
Member

Probably I found the solution of the mystery 🕵️‍♂️

BottleImpl::read() calls bool BottleImpl::isComplete(char* txt) and if the string read from the connection reader is not complete he tries to read the rest from the socket.

In this case the string with only one " is considered as not complete so it waits the rest of the string.

The only way to fix it is to check the inputs before sending requests to the yarpserver, I don't think that the parsing of the bottle is bugged(in this case 😛) the string is correctly marked as incomplete

@drdanz
Copy link
Member

drdanz commented Feb 22, 2018

Does yarpserver get stuck if it receives such a string?
Sending commands through YARP is not the only way to send commands to yarpserver, so checking the input before sending the request is a good practice, but the server should not be in the "incomplete" state forever, perhaps a timeout would help

@drdanz drdanz added the Affects: YARP v2.3.72 This is a known issue affecting YARP v2.3.72 label Feb 22, 2018
@Nicogene
Copy link
Member

Nicogene commented Feb 23, 2018

With @damn1 and @drdanz we found a possible solution:
if you put

    delegate->getInputStream().setReadTimeout(1.0);
    delegate->getOutputStream().setWriteTimeout(1.0);

inside yarp::os::impl::NameserTwoWayStream, all the requests to yarpserver will have a timeout of 1.0 seconds.

In this way if you put only one " the string will be marked as incomplete, and the nameserver will wait only one second for the rest of the message, and then if it doesn't receive anything it will close the connection.

With this fix yarp exists \" doesn't get stuck but it have this error message that it is quite misleading:

yarp: No connection to nameserver
yarp: *** try running: yarp detect ***

Any suggestions for better fixes ?
We could find a way to print an error message more appropriate 🤔

@Nicogene Nicogene changed the title Various problem arise if a yarpmanager xml file contains a " in a port name Yarpserver get stuck if it reads a string with a single " Feb 23, 2018
@pattacini
Copy link
Member

pattacini commented Feb 23, 2018

Doable for me @Nicogene 👍

Anyway, is there any room for unexpected behaviors?

In other words, is there at the moment any case where the connection may stay freezed for slightly more than 1 second and then restored soon afterward (e.g. very overloaded network due to complicated demos)?

@drdanz
Copy link
Member

drdanz commented Feb 23, 2018

I suggest to add a "--timeout" option (setting default 1.0) to yarpserver

@pattacini
Copy link
Member

The command line option is worthy, but I would make up a more meaningful name than just timeout.
As for the default, I'd be less strict; something like 2 or more seconds.

@lornat75
Copy link
Member

uhm, timeouts lead to the dark side...

@pattacini
Copy link
Member

Timeouts are an anti-pattern I know, but sometimes they're the only way out.

@lornat75
Copy link
Member

Setting a unique timeout on the yarpserver may be a limitation, but we could do it and see if it works out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Affects: YARP v2.3.72 This is a known issue affecting YARP v2.3.72 Component: GUI - yarpmanager Component: Library - YARP_os Component: Tool - yarpserver Issue Type: Bug Involves some intervention from a system administrator
Projects
None yet
Development

No branches or pull requests

8 participants