fieldrndservices / libssh2-labview

A LabVIEW library for SSH client support via libssh2
Apache License 2.0
21 stars 2 forks source link

SSHlib freeze during init #55

Open Volinger opened 2 years ago

Volinger commented 2 years ago

Hello,

I am currently struggling with an issue related to opening of new connection. It happens from time to time, that when I connect from PC to a linux based device, that LabVIEW gets frozen during execution of "Connect" API. After some debugging, I found that this is due to my device losing connection during execution of Connect API. If I disconnect device before this API, Connect API returns error 8146. In this case I can reset SSH connection. However, if I turn the device off during Connect API, call function node gets stuck.

I was checking also network traces and found, that if the device is disconnected before API execution, there is some "Reset acknowledge" reported after some timeout, after which call function node stops and I receive mentioned error. If the communication drops during "Connect" execution, then the message is not sent.

My feeling is that libSSH2 (or LV wrapper), is not handling the situation when connection begins to establish, but is not finished - or at least, if at some very specific time connection drops, message is not sent from the device to my PC and then the connection function gets frozen.

I am using connect function with timeout image but unfortunately it seems that in case of error which I face this timeout is not triggered (I saw the function call stuck for hours).

Do you please have any idea, how to tackle this issue?

volks73 commented 2 years ago

LabVIEW creates the TCP connection. Once the TCP connection has been established, the created "socket" is passed to the libssh2 library through the libssh2lv wrapper library to "elevate" the TCP socket to a SSH channel. The timeout is only used by LabVIEW to establish the TCP connection.

Since you are using the timeout but are in some infinite loop, this indicates to me it is something in the SSH handshake to elevate the TCP socket to a SSH channel within the libssh2 library. You may want to try setting a SSH timeout with the "Session.lvclass::Write Timeout" VI or property before using the "Connect" VI. According to the libssh2 documentation for the libssh2_session_set_timeout function:

By default or if you set the timeout to zero, libssh2 has no timeout for blocking functions.

The toolkit and wrapper library mimic the defaults of the libssh2 library. I think creating a SSH connection/elevating TCP to a SSH channel, is a blocking function. Thus, you are stuck in an infinite loop when the SSH connection fails.

I don't know if the "Connect" VI and underlying libssh2 function uses the timeout and/or if this is something that can only be set after the connection, a.k.a. handshake, process is complete. But, worth a try.