From 643697ba9c2580fd2092bd75b32e81cae5b3dfa7 Mon Sep 17 00:00:00 2001 From: Julius Pfrommer Date: Sun, 29 Sep 2024 23:35:45 +0200 Subject: [PATCH] feat(pubsub): Silence errors on PubSub connections with a timeout to avoid logging floods --- src/pubsub/ua_pubsub.h | 2 ++ src/pubsub/ua_pubsub_connection.c | 11 ++++++++--- src/pubsub/ua_pubsub_eventloop.c | 11 ++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/pubsub/ua_pubsub.h b/src/pubsub/ua_pubsub.h index daef39d65a7..0a6aff4fa6f 100644 --- a/src/pubsub/ua_pubsub.h +++ b/src/pubsub/ua_pubsub.h @@ -162,6 +162,8 @@ typedef struct UA_PubSubConnection { UA_UInt16 configurationFreezeCounter; + UA_DateTime silenceErrorUntil; /* Avoid generating too many logs */ + UA_Boolean deleteFlag; /* To be deleted - in addition to the PubSubState */ UA_DelayedCallback dc; /* For delayed freeing */ } UA_PubSubConnection; diff --git a/src/pubsub/ua_pubsub_connection.c b/src/pubsub/ua_pubsub_connection.c index 0cf31766fde..5986cada730 100644 --- a/src/pubsub/ua_pubsub_connection.c +++ b/src/pubsub/ua_pubsub_connection.c @@ -73,9 +73,14 @@ decodeNetworkMessage(UA_Server *server, UA_ByteString *buffer, size_t *pos, loops_exit: if(!processed) { - UA_LOG_INFO_CONNECTION(server->config.logging, connection, - "Dataset reader not found. Check PublisherId, " - "WriterGroupId and DatasetWriterId"); + UA_DateTime nowM = UA_DateTime_nowMonotonic(); + if(connection->silenceErrorUntil < nowM) { + UA_LOG_INFO_CONNECTION(server->config.logging, connection, + "Dataset reader not found. Check PublisherId, " + "WriterGroupId and DatasetWriterId. " + "(This error is now silenced for 10s.)"); + connection->silenceErrorUntil = nowM + (UA_DateTime)(10.0 * UA_DATETIME_SEC); + } /* Possible multicast scenario: there are multiple connections (with one * or more ReaderGroups) within a multicast group every connection * receives all network messages, even if some of them are not meant for diff --git a/src/pubsub/ua_pubsub_eventloop.c b/src/pubsub/ua_pubsub_eventloop.c index 03126e8de6d..c2e88452c95 100644 --- a/src/pubsub/ua_pubsub_eventloop.c +++ b/src/pubsub/ua_pubsub_eventloop.c @@ -253,9 +253,14 @@ PubSubChannelCallback(UA_ConnectionManager *cm, uintptr_t connectionId, } if(!processed) { - UA_LOG_WARNING_CONNECTION(server->config.logging, psc, - "Message received that could not be processed. " - "Check PublisherID, WriterGroupID and DatasetWriterID."); + UA_DateTime nowM = UA_DateTime_nowMonotonic(); + if(psc->silenceErrorUntil < nowM) { + UA_LOG_WARNING_CONNECTION(server->config.logging, psc, + "Message received that could not be processed. " + "Check PublisherID, WriterGroupID and DatasetWriterID. " + "(This error is now silenced for 10s.)"); + psc->silenceErrorUntil = nowM + (UA_DateTime)(10.0 * UA_DATETIME_SEC); + } } UA_UNLOCK(&server->serviceMutex);