Error publishing subscription. The session cannot be used because ActivateSession has not been called.
See original GitHub issueWe are using the opc-ua-client library to connect to multiple OPC UA servers, and we are having issues only with one server. We are using client library version 2.2.1 What we do in short:
- Open a channel
- Read a few tags
_channel = new UaTcpSessionChannel (
appDescription,
certificateStore,
ShowSignInDialog,
remoteEndpoint: new EndpointDescription {
EndpointUrl = DiscoveryUrl,
SecurityPolicyUri = securityPolicyUri,
SecurityMode = messageSecurityMode },
loggerFactory: EnableInternalLogs ? loggerFactory : new LoggerFactory(),
options: new UaTcpSessionChannelOptions()
{
TimeoutHint = SessionChannelTimeout
}
);
await _channel.OpenAsync().ConfigureAwait(false);
...
ReadValueId rVal = new ReadValueId
{
NodeId = BuildNodeId(namespaceIdx, id, idType),
AttributeId = AttributeIds.Value
};
ReadResponse response = await _channel.ReadAsync(new ReadRequest()
{
NodesToRead = new ReadValueId[] { rVal }
}).ConfigureAwait(false);
Log(LogLevel.Info, $"{rVal.NodeId.NamespaceIndex}:{rVal.NodeId.Identifier}={response.Results[0].Value}");
What happens:
- The result of tag readings is empty. We receive no values.
- After a minute or so the following error occurres and the communication is broken:
“Error publishing subscription. The session cannot be used because ActivateSession has not been called.”
- We tried different scenarios, but all the same.
- Using UAExpert everything works fine.
Here are all relevant logs, those marked [INTERNAL] are from the client library:
[2020-02-24 14:03:37.3566] [DEBUG] Creating a session with the server… [2020-02-24 14:03:37.3566] [DEBUG] SecurityPolicyUri: ‘http://opcfoundation.org/UA/SecurityPolicy#None’. [2020-02-24 14:03:37.3566] [DEBUG] SecurityMode: ‘None’. [2020-02-24 14:03:37.3625] [DEBUG] UserIdentity: ‘’. [2020-02-24 14:03:37.3625] [INFO] [INTERNAL] Discovering endpoints of ‘opc.tcp://192.168.1.120:4840’. [2020-02-24 14:03:37.3625] [DEBUG] [INTERNAL] Channel opening. [2020-02-24 14:03:37.4267] [DEBUG] [INTERNAL] Sending OpenSecureChannelRequest, Handle: 1 [2020-02-24 14:03:37.4622] [DEBUG] [INTERNAL] Received OpenSecureChannelResponse, Handle: 1 Result: 0x00000000 [2020-02-24 14:03:37.4737] [DEBUG] [INTERNAL] Channel opened. [2020-02-24 14:03:37.4737] [DEBUG] [INTERNAL] Sending GetEndpointsRequest, Handle: 2 [2020-02-24 14:03:37.4909] [DEBUG] [INTERNAL] Installed new security token 1. [2020-02-24 14:03:37.4960] [DEBUG] [INTERNAL] Received GetEndpointsResponse, Handle: 2 Result: 0x00000000 [2020-02-24 14:03:37.5047] [DEBUG] [INTERNAL] Channel closing. [2020-02-24 14:03:37.5082] [DEBUG] [INTERNAL] Sending CloseSecureChannelRequest, Handle: 3 [2020-02-24 14:03:37.5269] [ERROR] [INTERNAL] Error closing secure channel. Timeout occurred while processing the request. [2020-02-24 14:03:37.5269] [DEBUG] [INTERNAL] Channel closed. [2020-02-24 14:03:37.5325] [DEBUG] [INTERNAL] Success discovering endpoints of ‘opc.tcp://192.168.1.120:4840’. [2020-02-24 14:03:37.5374] [DEBUG] Client is building Anonymous identity… [2020-02-24 14:03:37.5374] [DEBUG] Done building identity. [2020-02-24 14:03:37.5374] [DEBUG] [INTERNAL] Channel opening. [2020-02-24 14:03:37.5387] [DEBUG] Opening channel with endpoint ‘opc.tcp://192.168.1.120:4840’. [2020-02-24 14:03:37.5610] [INFO] [INTERNAL] Opening session channel with endpoint ‘opc.tcp://192.168.1.120:4840’. [2020-02-24 14:03:37.5610] [INFO] [INTERNAL] SecurityPolicy: ‘http://opcfoundation.org/UA/SecurityPolicy#None’. [2020-02-24 14:03:37.5610] [INFO] [INTERNAL] SecurityMode: ‘None’. [2020-02-24 14:03:37.5610] [INFO] [INTERNAL] UserIdentity: ‘Workstation.ServiceModel.Ua.AnonymousIdentity’. [2020-02-24 14:03:37.5756] [DEBUG] [INTERNAL] Sending OpenSecureChannelRequest, Handle: 1 [2020-02-24 14:03:37.5790] [DEBUG] [INTERNAL] Received OpenSecureChannelResponse, Handle: 1 Result: 0x00000000 [2020-02-24 14:03:37.5835] [DEBUG] [INTERNAL] Sending CreateSessionRequest, Handle: 2 [2020-02-24 14:03:37.6029] [DEBUG] [INTERNAL] Installed new security token 1. [2020-02-24 14:03:37.6029] [DEBUG] [INTERNAL] Received CreateSessionResponse, Handle: 2 Result: 0x00000000 [2020-02-24 14:03:37.6120] [DEBUG] [INTERNAL] Sending ActivateSessionRequest, Handle: 3 [2020-02-24 14:03:37.6321] [DEBUG] [INTERNAL] Received ActivateSessionResponse, Handle: 3 Result: 0x00000000 [2020-02-24 14:03:37.6368] [DEBUG] [INTERNAL] Sending ReadRequest, Handle: 4 [2020-02-24 14:03:37.6636] [DEBUG] [INTERNAL] Received ReadResponse, Handle: 4 Result: 0x00000000 [2020-02-24 14:03:37.6701] [DEBUG] [INTERNAL] Sending CreateSubscriptionRequest, Handle: 5 [2020-02-24 14:03:37.6806] [DEBUG] [INTERNAL] Received CreateSubscriptionResponse, Handle: 5 Result: 0x00000000 [2020-02-24 14:03:37.6831] [DEBUG] [INTERNAL] Channel opened. [2020-02-24 14:03:37.6831] [DEBUG] Opened channel with endpoint ‘opc.tcp://192.168.1.120:4840’. [2020-02-24 14:03:37.6953] [DEBUG] [INTERNAL] Sending PublishRequest, Handle: 6 [2020-02-24 14:03:37.6988] [DEBUG] [INTERNAL] Sending ReadRequest, Handle: 7 [2020-02-24 14:03:37.7046] [DEBUG] [INTERNAL] Received ReadResponse, Handle: 7 Result: 0x00000000 [2020-02-24 14:03:37.7078] [INFO] 3:0001_Alarms= [2020-02-24 14:03:37.7078] [DEBUG] [INTERNAL] Sending ReadRequest, Handle: 8 [2020-02-24 14:03:37.7078] [DEBUG] [INTERNAL] Sending PublishRequest, Handle: 9 [2020-02-24 14:03:37.7078] [DEBUG] [INTERNAL] Sending PublishRequest, Handle: 10 [2020-02-24 14:03:37.7145] [DEBUG] [INTERNAL] Received ReadResponse, Handle: 8 Result: 0x00000000 [2020-02-24 14:03:37.7145] [INFO] 3:0002_State= [2020-02-24 14:03:37.7145] [DEBUG] [INTERNAL] Sending ReadRequest, Handle: 11 [2020-02-24 14:03:37.7248] [DEBUG] [INTERNAL] Received ReadResponse, Handle: 11 Result: 0x00000000 [2020-02-24 14:03:37.7248] [INFO] 3:0003_Mode= [2020-02-24 14:03:37.7248] [INFO] Created subscription. [2020-02-24 14:03:38.6809] [DEBUG] [INTERNAL] Received PublishResponse, Handle: 6 Result: 0x00000000 [2020-02-24 14:03:38.6855] [DEBUG] [INTERNAL] Sending PublishRequest, Handle: 12 [2020-02-24 14:04:08.6908] [DEBUG] [INTERNAL] Received PublishResponse, Handle: 9 Result: 0x00000000 [2020-02-24 14:04:08.6908] [DEBUG] [INTERNAL] Sending PublishRequest, Handle: 13 [2020-02-24 14:04:08.6970] [DEBUG] [INTERNAL] Received ServiceFault, Handle: 13 Result: 0x80270000 [2020-02-24 14:04:08.7014] [ERROR] [INTERNAL] Error publishing subscription. The session cannot be used because ActivateSession has not been called.
Do we do something wrong or is there a flaw in the client library? Any help is highly appreciated!
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (9 by maintainers)
Top GitHub Comments
Yes, let me explain. The S7-1500 setting ‘Max session timeout’ is the number of seconds that a session connection may be unused before being closed by the server. In this version of firmware, the default timeout is 30 seconds (rather a short time). So, if a opc client does nothing with the connection for 30 seconds, the opc server will just close the connection. The UaTcpSessionChannel uses a background subscription as a keep-alive message. This subscription has a keep-alive interval of 30 seconds. Unfortunately the session timeout always won the battle and would close the connection. I plan to change this keep-alive interval to be 5 seconds, the same as UAExpert. This 5 second interval is only for the single internal subscription. Your subscriptions should use what is best for your program. The defaults will remain 30 secs for keep-alive, 3 * 30 seconds for lifetime.
Ok. I reproduced the same issue. That’s the first step in fixing this!