Skip to content

Error creating session on OPCUA client #586

@orzaez

Description

@orzaez

Describe the bug
A session establishment issue occurs when attempting to connect to the OPC UA server. The error indicates that a request is missing from the pending queue.

Attempt to connect to the OPC UA server at 10.14.26.253 on port 4070. The connection is successfully established, and a CreateSessionRequest is sent. The server responds with a CreateSessionResponse. An ActivateSessionRequest is sent. The error occurs: session pending queue error, because element not exist.
Expected behavior
The ActivateSessionRequest should be processed successfully, and the session should be fully established without errors.

Code
These are my criticals methods:

OpcUaStackCore::SecureChannelClientConfig::SPtr ComunicationOPCUA::configureSecureChannel(const std::string &endpointURL, const std::string &securityPolicy,const std::string &securityMode,const std::string &clientCertificate,const std::string &privateKey,uint32_t timeout)
	{
		auto secureChannelConfig = boost::make_shared<OpcUaStackCore::SecureChannelClientConfig>();
		secureChannelConfig->endpointUrl(endpointURL);

		// 1. SecurityMode
		OpcUaStackCore::SecurityMode sm = OpcUaStackCore::SecurityMode::SM_None;
		// 2.  SecurityPolicy
		OpcUaStackCore::SecurityPolicy sp = OpcUaStackCore::SecurityPolicy::SP_None;
	return secureChannelConfig;
	}

OpcUaStackClient::SessionConfig::SPtr ComunicationOPCUA::configureSession( const std::string &sessionName, const std::string &user, const std::string &password ) 
	{
		try {
			auto extensibleParam = boost::make_shared<OpcUaStackCore::ExtensibleParameter>();
			
			auto anonymousToken = boost::make_shared<OpcUaStackCore::AnonymousIdentityToken>();
			anonymousToken->policyId("anonymous_policy");

			OpcUaStackCore::OpcUaNodeId anonymousTypeId(OpcUaId_AnonymousIdentityToken_Encoding_DefaultBinary, 0);
			extensibleParam->registerFactoryElement<OpcUaStackCore::AnonymousIdentityToken>(anonymousTypeId);
			extensibleParam->parameterTypeId(anonymousTypeId);

			auto token = extensibleParam->parameter<OpcUaStackCore::AnonymousIdentityToken>();
			if (!token) {
				throw std::runtime_error("AnonymousIdentityToken is null or not registered properly.");
			}
			*token = *anonymousToken;
			
			auto activateSessionRequest = boost::make_shared<OpcUaStackCore::ActivateSessionRequest>();
	
			activateSessionRequest->userIdentityToken(extensibleParam);



		auto sessionConfig = boost::make_shared<OpcUaStackClient::SessionConfig>();
        sessionConfig->sessionName(sessionName);
return sessionConfig;

		}
		catch (const std::exception &err) {
			Logger::error("Err0281", err.what(), "", true);
			return nullptr; // Detener la ejecución en caso de error
		}
	}
bool ComunicationOPCUA::connectSessionService()
	{
		try 
		{
			sessionService->syncConnect();

			OpcUaStackCore::Log::logout(OpcUaStackCore::LogLevel::Info, "Async connection initiated.");
			return true;
		}
		catch (const std::exception &e) 
		{
			OpcUaStackCore::Log::logout(OpcUaStackCore::LogLevel::Error, 
				"Error during OPC UA async connection: " + std::string(e.what()));
			isConnected = false;
			return false;
		}
	}

Logs

INF [7fa7a17fa000] resolver complete
INF [7fa7a17fa000] connect secure channel to server: Address=<10.14.26.253>, Port=<4070>
INF [7fa7a17fa000] secure channel to server connected: Address=<10.14.26.253>, Port=<4070>
DBG [7fa7a17fa000] session send CreateSessionRequest: RequestId=<1>, SessionName=<urn:DTG-OP-165:UnifiedAutomation:UaExpert>
DBG [7fa7a17fa000] session recv CreateSessionResponse: RequestId=<1>, SessionName=<urn:DTG-OP-165:UnifiedAutomation:UaExpert>, AuthenticationToken=<i=0>
DBG [7fa7a17fa000] session send ActivateSessionRequest: RequestId=<2>, SessionName=<urn:DTG-OP-165:UnifiedAutomation:UaExpert>, AuthenticationToken=<i=0>
ERR [7fa7a17fa000] session pending queue error, because element not exist: RequestId=<2>, SessionName=<urn:DTG-OP-165:UnifiedAutomation:UaExpert>, AuthenticationToken=<i=0>, TypeId=<i=397>, RequestHandle=<2>

OS: [e.g. Ubuntu 20.04]
Version: [e.g. OPC UA Stack 1.4.8]
Additional context
The error suggests that the ActivateSessionRequest is missing or was removed prematurely from the pending queue. This might be caused by a timing issue or an incorrect request handling within the OPC UA client or server.

PLEASE HELP!! :))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions