Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Got Bad_SubscriptionIdInvalid error while trying to remove items from subscription.
August 25, 2022
11:56, EEST
Avatar
amj005
Member
Members
Forum Posts: 17
Member Since:
July 27, 2021
sp_UserOfflineSmall Offline

Hi,
I am getting below Bad_SubscriptionIdInvalid exception, while removing items from subscription. Can you let me know why we get that?

Exception stack trace:
OPCConnection: Error while reconnecing subscription group PT1S-PT0S-async_11 for OPCUAConnection:
com.prosysopc.ua.ServiceException: ServiceFault [ResponseHeader=”ResponseHeader [Timestamp=”08/17/22 14:57:29.3660000 GMT”, RequestHandle=”1223612″, ServiceResult=”Bad_SubscriptionIdInvalid (0x80280000) “The subscription id is not valid.””, ServiceDiagnostics=”Diagnostic Info:
“, StringTable=”null”, AdditionalHeader=”null”]”]
at com.prosysopc.ua.client.Subscription.b(SourceFile:1222) [prosys-opc-ua-sdk-client-server-4.7.2-13.jar!/:na]
at com.prosysopc.ua.client.Subscription.deleteMonitoredItems(SourceFile:1731) [prosys-opc-ua-sdk-client-server-4.7.2-13.jar!/:na]
at com.prosysopc.ua.client.Subscription.removeItems(SourceFile:731) [prosys-opc-ua-sdk-client-server-4.7.2-13.jar!/:na]
at com.prosysopc.ua.client.Subscription.removeItems(SourceFile:697) [prosys-opc-ua-sdk-client-server-4.7.2-13.jar!/:na]

Thanks.

August 25, 2022
12:28, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 221
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

The Bad_SubscriptionIdInvalid StatusCode is generated by the Server in response to attempting to remove MonitoredItems from the Subscription. The specification simply describes this StatusCode to mean that “The subscription id is not valid”. This could be caused by the Subscription no longer existing on the Server. Has the Server been restarted or could the Subscription have timed out before removing MonitoredItems was attempted?

Are you able to check the Server’s logs for its response to receiving a DeleteMonitoredItems request to which it responds with that StatusCode?

Also, has the Server been implemented with Prosys OPC UA SDK for Java?

August 25, 2022
14:50, EEST
Avatar
amj005
Member
Members
Forum Posts: 17
Member Since:
July 27, 2021
sp_UserOfflineSmall Offline

Hi,
Thanks for the reply.
I had got the subscription alive listener ‘onTimeout’ method before that.
Can you provide full details when this call back will be called? It helps handle this.

I do not have access to server logs and details.

Further, what is the right way to handle the onTimeout and onLifetimeTimeout? Can we remove the subscription and add new subscription, to continue get the data?

Thanks.

August 25, 2022
15:25, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 221
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

The onTimeout method of SubscriptionAliveListener is called when more time than PublishingInterval (default value 1000 ms) multiplied by MaxKeepAliveCount (default value 20) multiplied by TimeoutDetectionFactor (default value 1.3) has elapsed since last contact from the Server. Note, that if you have set PublishingInterval to, e.g. 100 ms, the Subscription would time out after 2.6 seconds of inactivity.

The onTimeout being called implies that either the Server isn’t sending new notifications or keep alive messages as often as the Client has requested and the Server has agreed to do or there is a communication error between the Client and the Server. In the latter case the onStateChange method of ServerStatusListener should have been called with ServerState CommunicationFault to indicate the error.

If either the onTimeout or the onLifetimeTimeout method has been called, it is possible that the Server has already deleted the Subscription and its MonitoredItems which would explain why Client requesting to delete MonitoredItems would cause the Bad_SubscriptionIdInvalid for a Subscription that no longer exists on the Server. If the Subscription no longer exists, you will most likely get the same StatusCode when attempting to remove the Subscription, so you can recreate the Subscription and its MonitoredItems. I would suggest to try deleting the MonitoredItems and the Subscription anyway to guarantee that they no longer exist on the Server.

August 25, 2022
16:00, EEST
Avatar
amj005
Member
Members
Forum Posts: 17
Member Since:
July 27, 2021
sp_UserOfflineSmall Offline

Thanks a lot !
Really glad to hear the clear details of onTimeout, with the multipliers. 🙂

Can you suggest on below?
As of now, we are seeing the timeouts coming up after few days of starting client. So, I have implemented to recreate subscription, if we encounter that. Any other suggestion on handling such issues and make sure we are getting continuous data without breaks and issues in application?

August 26, 2022
8:32, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 221
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

A clarification to the previous message, onTimeout means that the Subscription hasn’t send data or keep alive in the expected period of time. While that could imply that the Subscription no longer exists on the Server, it could also be caused by the Server being incapable of sending messages in the expected time frame for some other reason, e.g. connection break. onLifetimeTimeout means that the Subscription hasn’t send anything and it also should have been deleted on the Server side. In short, onTimeout implies that something might be wrong with Subscription, the Server in general or the connection between the Client and the Server and onLifetimeTimeout means that the Subscription no longer exists on the Server for certain.

Though, it is worth mentioning that at the moment of writing this there is still a mistake in the specification that says that MaxKeepAliveCount is used instead of LifetimeCount to determine when the Subscription is deleted. Later in the specification the purpose of KeepAliveCounter and LifetimeCounter of a Subscription are explained in more detail correcting the earlier mistakes. Still, there have been cases where Server’s have used MaxKeepAliveCount in place of LifetimeCount to determine when to delete a Subscription, so the Server you’re connecting to could actually delete the Subscription when onTimeout is triggered.

For more information on Subscriptions, see https://reference.opcfoundation.org/Core/Part4/5.13.1/

If you’re expecting there to be connection breaks between the Client and the Server that might prevent the Subscription from sending data and keep alive messages, you could increase the RequestedLifetimeCount (and possibly RequestedMaxKeepAliveCount) when creating the Subscription to increase the time it takes before the Subscription is deleted on the Server. The default value for RequestedLifetimeCount is 60, which means that with default RequestedPublishingInterval of 1000 ms, the Subscription will be deleted if there is no communication between the Client and the Server for 60 seconds. If you’re expecting longer connection breaks than that, you should increase the RequestedLifetimeCount. And if you use a shorter RequestedPublishingInterval without changing RequestedLifetimeCount, the Subscription will expire even sooner.

On the other hand, if you’re expecting that your Client might be the side that suddenly stops communicating with the Server, the Server won’t know that it can delete the Subscription and won’t do it until the time determined by RequestedLifetimeCount has expired. Such Subscriptions will continue to consume Server resources until their lifetime expires. If the Server is running on hardware with low computing resources, you must take this into consideration before giving the Subscription arbitrarily long RequestedLifetimeCount.

September 8, 2022
18:47, EEST
Avatar
amj005
Member
Members
Forum Posts: 17
Member Since:
July 27, 2021
sp_UserOfflineSmall Offline

One more thing, how does the prosys handle the communication_fault from the server and what are the steps done by prosys? Example: Does it wait for some time and try auto reconnect? So, that helps us to handle reconnection manually on client side, if something goes bad and to make sure application works without downtime.

September 9, 2022
8:42, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 221
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

By default the Status of the Server is checked approximately once every second and when a communication fault occurs, the Client will attempt to reconnect to the Server periodically until reconnecting succeeds. After creating a SecureChannel successfully, the Client will attempt to reactivate its previous Session, if it still exists. Otherwise, a new Session will be created and activated. If the Client was able to reactivate its previous Session, it will ask the Server to do a Republish for all Subscriptions. If the Subscriptions no longer exist, the Client will recreate the Subscriptions and their MonitoredItems. Recreating the Subscriptions and MonitoredItems also happens when the Client has to create and activate a new Session.

In short, the Client should be doing everything automatically when reconnecting to a Server after a communication fault.

However, it is important to not call the reconnect method of UaClient instance manually when automatic reconnecting has been enabled, which is the the default for UaClient instances. This could cause the method to be executed in two threads at the same time, which can cause errors as both of the methods would be modifying the same internal parameters of the UaClient instance at the same time. If you would prefer to handle reconnecting manually with a ServerStatusListener for example, you must disable automatic reconnecting by calling the setAutoReconnect(boolean doAutoReconnect) method of the UaClient instance with doAutoReconnect set to false.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 267

Currently Online:
5 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 122

pramanj: 86

ibrahim: 74

rocket science: 65

kapsl: 57

gjevremovic: 49

Sabari: 46

Xavier: 42

TimK: 41

fred: 41

Member Stats:

Guest Posters: 0

Members: 3344

Moderators: 17

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1300

Posts: 5561

Newest Members:

UPtato42, fblvicky6629601, elliebloomer44, Manuelagibe, justinafavenc54, sarlaman9, nancymcneal1, elztaim591797, JeffreyAidet, sameisenhower7

Moderators: Jouni Aro: 946, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 836, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 41, Niklas Nurminen: 0, Matti Siponen: 221, Lusetti: 0

Administrators: admin: 1