From 80105ee6851e13da4b6fe52807554779c929fe2c Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 4 Nov 2019 18:24:08 +0100 Subject: [PATCH 1/2] try-catch block added to KeepAliveThread::Run() exception thrown in KeepAliveThread::Run() cannot be caught in client application and cause app crash when OPC-UA connection is drop. Adding try-catch block avoid this and gives client app opportunity to create new OPC-UA connection without crash. --- src/client/client.cpp | 55 ++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index b6d35eae..4d4367e3 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -53,35 +53,46 @@ void KeepAliveThread::Run() while (!StopRequest) { - int64_t t_sleep = Period * 0.7; - LOG_DEBUG(Logger, "keep_alive_thread | sleeping for: {}ms", t_sleep); + try + { + int64_t t_sleep = Period * 0.7; + LOG_DEBUG(Logger, "keep_alive_thread | sleeping for: {}ms", t_sleep); - std::unique_lock lock(Mutex); - std::cv_status status = Condition.wait_for(lock, std::chrono::milliseconds(t_sleep)); + std::unique_lock lock(Mutex); + std::cv_status status = Condition.wait_for(lock, std::chrono::milliseconds(t_sleep)); - if (status == std::cv_status::no_timeout) - { - break; - } + if (status == std::cv_status::no_timeout) + { + break; + } - LOG_DEBUG(Logger, "keep_alive_thread | renewing secure channel"); + LOG_DEBUG(Logger, "keep_alive_thread | renewing secure channel"); - OpenSecureChannelParameters params; - params.ClientProtocolVersion = 0; - params.RequestType = SecurityTokenRequestType::Renew; - params.SecurityMode = MessageSecurityMode::None; - params.ClientNonce = std::vector(1, 0); - params.RequestLifeTime = Period; - OpenSecureChannelResponse response = Server->OpenSecureChannel(params); + OpenSecureChannelParameters params; + params.ClientProtocolVersion = 0; + params.RequestType = SecurityTokenRequestType::Renew; + params.SecurityMode = MessageSecurityMode::None; + params.ClientNonce = std::vector(1, 0); + params.RequestLifeTime = Period; + OpenSecureChannelResponse response = Server->OpenSecureChannel(params); - if ((response.ChannelSecurityToken.RevisedLifetime < Period) && (response.ChannelSecurityToken.RevisedLifetime > 0)) - { - Period = response.ChannelSecurityToken.RevisedLifetime; - } + if ((response.ChannelSecurityToken.RevisedLifetime < Period) && (response.ChannelSecurityToken.RevisedLifetime > 0)) + { + Period = response.ChannelSecurityToken.RevisedLifetime; + } - LOG_DEBUG(Logger, "keep_alive_thread | read a variable from address space to keep session open"); + LOG_DEBUG(Logger, "keep_alive_thread | read a variable from address space to keep session open"); - NodeToRead.GetValue(); + NodeToRead.GetValue(); + } + catch (const std::exception &e) + { + LOG_ERROR(Logger, "keep_alive_thread | error", e.what()); + } + catch (...) + { + LOG_ERROR(Logger, "keep_alive_thread | error unknown"); + } } Running = false; From 518eaed0f00e8b17dce8704033b4d53e8d0e0e03 Mon Sep 17 00:00:00 2001 From: Jaroslav Beran <72652580+j4r0u53k@users.noreply.github.com> Date: Tue, 24 Aug 2021 18:51:53 +0200 Subject: [PATCH 2/2] Include algorithm header in model_impl.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With newer versions of GCC, the error: ‘for_each’ is not a member of ‘std’ is triggered unless the algorithm header from std lib is included. --- src/core/model_impl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/model_impl.h b/src/core/model_impl.h index 0f548c5a..84c75468 100644 --- a/src/core/model_impl.h +++ b/src/core/model_impl.h @@ -21,6 +21,8 @@ #include +#include + namespace OpcUa { namespace Model