-
Notifications
You must be signed in to change notification settings - Fork 9
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
Websocket connection is not closed, when tcp client disconnects #38
Comments
Thanks @toewsar for the ticket. To make the change easier (and to add a test case for it), would you be able to answer the following questions?
|
Yes, you can test it. I tried to tunnel the CODESYS IDE <-> CODESYS Gateway. I'll try to test it today with 1.5.0. |
@toewsar This depends in which mode you start the c8ylp. In server mode the c8ylp acts like a server so you have to shutdown it manually to terminate the websocket connection. So if the TCP-Client disconnects you have to make sure to also terminate the c8ylp server if this is desired. @reubenmiller In 1.5 we had the script mode doing exactly that: Terminate c8ylp when tcp client disconnects. Not sure if we should add a flag to server or we can achieve that with connect command. |
@switschel There is already a retry settings which could be set to 0 to disable trying to reestablish the connection, for example: c8ylp server --reconnects 1 device01 Though maybe even 1 reconnect is too much in this case, but it could help. |
Or using the in-built "command" plugin (in v2 only) c8ylp plugin command --env-file .env --reconnects 1 device01 './runsomething $PORT' Here is the plugin help
|
@reubenmiller reconnect 0 will set it to infinite reconnects |
@switschel Yes that sounds reasonable. Though I still want to make sure that this is the actual issue though, and not some other internal workings with the connection/disconnection of the sockets. |
Btw. it is already implemented: https://github.com/SoftwareAG/cumulocity-remote-access-local-proxy/blob/27b7781df2342105f3aa90e2eee6f8d1664a3b88/c8ylp/websocket_client/ws_client.py#L177 @toewsar Can you try if adding '--reconnects -1' is the behavior you expect to have? |
That is the right spot, however the logic is inverted. It should be (self.max_retries == -1), as the if statement is to decide if the connection should be terminated. I have made a change on this fix/disable-reconnects branch You can try out the wip branch which supports the reconnect=-1 properly using:
I noticed that this might produce an other error when trying to write to a closed socket when it disconnects, but it should at least show that it is possible. |
I tried, but without success. The problem ist, that the tcp-server does not forward the close to the websocket client. |
@reubenmiller I added a WS stop if the TCP Client is disconnected in your fix branch. |
My connection between CODESYS <-> Gateway seems to be stable now. |
@switschel I've updated the PR #40 to hide the reconnects option and print out a warning that it is deprecated (so that we don't break any existing scripts). |
@toewsar This has been fixed and released in v2.1.2 |
Some protocols do not keep the connection open. And if they open again they assume to have a clean session.
But because the c8ylp does not disconnect the websocket, the tcp connection on the device side remains open.
Therefore the c8ylp have to close the websocket conenction, if the tcp client disconnects. This would notify the device that the connection is closed and the device would then disconnect the tcp server, too.
I would be happy if you could fix this.
The text was updated successfully, but these errors were encountered: