Skip to content

Commit

Permalink
feat(pubsub): Silence errors on PubSub connections with a timeout to …
Browse files Browse the repository at this point in the history
…avoid logging floods
  • Loading branch information
jpfr committed Sep 29, 2024
1 parent d85b390 commit 643697b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/pubsub/ua_pubsub.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/pubsub/ua_pubsub_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/pubsub/ua_pubsub_eventloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 643697b

Please sign in to comment.