'Close OPC-UA connections before create a new one

Using the example Qt OPC UA Viewer Example if I kill the process without disconnecting the client, for some time I cannot connect anymore to the OpcUA server:

qt.opcua.plugins.open62541.sdk.client: "Client Status: ChannelState: Open, SessionState: Closed, ConnectStatus: Good"
qt.opcua.plugins.open62541.sdk.client: "Selected Endpoint opc.tcp://192.168.1.50:4840 with SecurityMode None and SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None"
qt.opcua.plugins.open62541.sdk.client: "Selected UserTokenPolicy Anonymous-[0]-None-None with UserTokenType Anonymous and SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None"
qt.opcua.plugins.open62541.sdk.client: "Received a ServiceFault response"
qt.opcua.plugins.open62541.sdk.client: "The ServiceResult has the StatusCode BadTooManySessions"
qt.opcua.plugins.open62541.sdk.client: "Client Status: ChannelState: Open, SessionState: Closed, ConnectStatus: BadTooManySessions"
qt.opcua.plugins.open62541.sdk.client: "Client Status: ChannelState: Closed, SessionState: Closed, ConnectStatus: BadTooManySessions"
qt.opcua.plugins.open62541: Open62541: Failed to connect

As far as I understand this is because the server accept only one connection and if it's not properly closed it does not accept new connections.

Because during development it may happen to kill the process (or it just crashes due to a bug) is there a way to close the pending connection (if any) before attempt a new one?

I'm running Qt 6.2.0 under Ubuntu 20.04.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source