locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
480 stars 129 forks source link

Make sure subscriptions are kept alive #187

Closed svanharmelen closed 2 years ago

svanharmelen commented 2 years ago

We noticed issues with several different OPC servers were the session was still there, but no data was flowing anymore. After investigating it turned out that the session was properly kept alive, but the subscription weren't. So they were expired and didn't send data anymore, yet nothing was triggered or notified to let the caller know this was happening.

The changes is this PR introduce a keep alive mechanism for subscriptions and adds the states BadNoSubscriptions and BadSubscriptionIdInvalid as fatal states that cause the session to close so it can be restarted again...

Text from the web that describes the used fields:

The client’s responsibility is to send PublishRequests to the server, in order to enable
the server to send PublishResponses back. The PublishResponses are used to deliver
the notifications: but if there are no PublishRequests, the server cannot send a
notification to the client.

The server will also verify that the client is alive by checking that new PublishRequests
are received – LifeTimeCount defines the number of PublishingIntervals to wait for a new
PublishRequest, before realizing that the client is no longer active. The Subscription is
then removed from the server.