You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by "Deedss (via GitHub)" <gi...@apache.org> on 2025/01/06 20:04:50 UTC

[PR] Expand logging information when genericEvent is waiting (celix)

Deedss opened a new pull request, #780:
URL: https://github.com/apache/celix/pull/780

   First time commit here, 
   
   When making use of celix, situations can occur that a fired genericEvent is not yet finished, resulting in multiple warning messages being printed in the logging. These messages contain very limited information on which event from which bundle is waiting.
   
   Hence this pull request to update the warning message with more information, containing eventName, eventId, bundleName and bundleId. This should help in deducing which generic Events from which bundles are waiting a long time.
   
   Also added an environment variable to support setting of the timeout of generic events, similar as to how scheduled events have the variable for setting the timeout in seconds.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "pnoltes (via GitHub)" <gi...@apache.org>.
pnoltes commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1905920793


##########
libs/framework/src/framework.c:
##########
@@ -2686,14 +2704,26 @@ static bool celix_framework_isGenericEventInProgress(celix_framework_t* fw, long
 
 void celix_framework_waitForGenericEvent(celix_framework_t* fw, long eventId) {
     assert(!celix_framework_isCurrentThreadTheEventLoop(fw));
-    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(5);
+    double logTimeoutInSeconds =
+        celix_framework_getConfigPropertyAsDouble(fw,
+                                                  CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS,
+                                                  CELIX_DEFAULT_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS,
+                                                  NULL);
+    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(logTimeoutInSeconds);
     celixThreadMutex_lock(&fw->dispatcher.mutex);
+    celix_framework_event_t* event = celix_framework_getGenericEvent(fw, eventId);

Review Comment:
   Note that `celix_framework_isGenericEventInProgress` checks whether the event can be found in the eventQueue or dynamicEventQueue and return true if found.
   
   Imo the  `celix_framework_isGenericEventInProgress` function can be removed and instead a check for `if (event /*event exists, so in progress*/) {` can be done.  
   



##########
libs/framework/src/framework.c:
##########
@@ -2686,14 +2704,26 @@ static bool celix_framework_isGenericEventInProgress(celix_framework_t* fw, long
 
 void celix_framework_waitForGenericEvent(celix_framework_t* fw, long eventId) {
     assert(!celix_framework_isCurrentThreadTheEventLoop(fw));
-    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(5);
+    double logTimeoutInSeconds =
+        celix_framework_getConfigPropertyAsDouble(fw,
+                                                  CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS,
+                                                  CELIX_DEFAULT_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS,
+                                                  NULL);
+    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(logTimeoutInSeconds);
     celixThreadMutex_lock(&fw->dispatcher.mutex);
+    celix_framework_event_t* event = celix_framework_getGenericEvent(fw, eventId);
     while (celix_framework_isGenericEventInProgress(fw, eventId)) {
         celix_status_t waitStatus =
             celixThreadCondition_waitUntil(&fw->dispatcher.cond, &fw->dispatcher.mutex, &logAbsTime);
         if (waitStatus == ETIMEDOUT) {
-            fw_log(fw->logger, CELIX_LOG_LEVEL_WARNING, "Generic event with id %li not finished.", eventId);
-            logAbsTime = celixThreadCondition_getDelayedTime(5);
+            fw_log(fw->logger,
+                   CELIX_LOG_LEVEL_WARNING,
+                   "Generic event '%s' (id=%li) for bundle '%s' (id=%li) not finished",

Review Comment:
   Nice that some more info is printed about the event 👍 



##########
libs/framework/src/framework.c:
##########
@@ -2686,14 +2704,26 @@ static bool celix_framework_isGenericEventInProgress(celix_framework_t* fw, long
 
 void celix_framework_waitForGenericEvent(celix_framework_t* fw, long eventId) {
     assert(!celix_framework_isCurrentThreadTheEventLoop(fw));
-    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(5);
+    double logTimeoutInSeconds =

Review Comment:
   Good to have this configureable, but in the current setup every call to `celix_framework_waitForGenericEvent` will check the environment. I think this is not needed, maybe retrieving this value during framework creating and store it the framework structure. Note that if this is done during framework create  no mutex protection is needed, because the value will only be written once. 



##########
libs/framework/gtest/src/CelixFrameworkTestSuite.cc:
##########
@@ -88,6 +88,34 @@ TEST_F(CelixFrameworkTestSuite, TimedWaitEventQueueTest) {
     EXPECT_EQ(CELIX_SUCCESS, status);
 }
 
+TEST_F(CelixFrameworkTestSuite, GenericEventTimeoutPropertyTest) {

Review Comment:
   Nice that there is also a test :)



##########
libs/framework/include/celix_constants.h:
##########
@@ -281,6 +281,21 @@ extern "C" {
  */
 #define CELIX_DEFAULT_ALLOWED_PROCESSING_TIME_FOR_SCHEDULED_EVENT_IN_SECONDS 2.0
 
+/*!
+ * @brief Celix framework environment property (named "CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS")
+ * to configure the allowed processing time for a generic event callback or a remove callback before a warning
+ * log message is printed that the processing time is too long.
+ * Should be a double value in seconds.
+ */
+#define CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS                                                   \

Review Comment:
   Could you also add this information to documents/framework.md and as C++ constexpr to libs/framework/include/celix/Constants.h



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "pnoltes (via GitHub)" <gi...@apache.org>.
pnoltes commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1907667272


##########
libs/framework/src/framework_private.h:
##########
@@ -188,6 +188,8 @@ struct celix_framework {
             int nbEvent; // number of pending generic events
         } stats;
         celix_long_hash_map_t *scheduledEvents; //key = scheduled event id, entry = celix_framework_scheduled_event_t*. Used for scheduled events
+
+        double genericEventTimeout; // Timeout for printing an warning on unfinished generic events

Review Comment:
   nitpick: rename to `genericEventTimeoutInSecond` so that it is clear that the timeout unit of measurement is seconds. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "PengZheng (via GitHub)" <gi...@apache.org>.
PengZheng commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1911968571


##########
libs/framework/src/framework.c:
##########
@@ -2663,38 +2667,43 @@ long celix_framework_nextScheduledEventId(framework_t *fw) {
     return __atomic_fetch_add(&fw->dispatcher.nextScheduledEventId, 1, __ATOMIC_RELAXED);
 }
 
-/**
- * @brief Checks if a generic event with the provided eventId is in progress.
- */
-static bool celix_framework_isGenericEventInProgress(celix_framework_t* fw, long eventId) {
-    // precondition fw->dispatcher.mutex locked)
+static celix_framework_event_t* celix_framework_getGenericEvent(celix_framework_t* fw, long eventId) {
+    // precondition fw->dispatcher.mutex locked
     for (int i = 0; i < fw->dispatcher.eventQueueSize; ++i) {
         int index = (fw->dispatcher.eventQueueFirstEntry + i) % fw->dispatcher.eventQueueCap;
         celix_framework_event_t* e = &fw->dispatcher.eventQueue[index];
         if (e->type == CELIX_GENERIC_EVENT && e->genericEventId == eventId) {
-            return true;;
+            return e;
         }
     }
     for (int i = 0; i < celix_arrayList_size(fw->dispatcher.dynamicEventQueue); ++i) {
         celix_framework_event_t* e = celix_arrayList_get(fw->dispatcher.dynamicEventQueue, i);
         if (e->type == CELIX_GENERIC_EVENT && e->genericEventId == eventId) {
-            return true;
+            return e;
         }
     }
-    return false;
+    return NULL;
 }
 
 void celix_framework_waitForGenericEvent(celix_framework_t* fw, long eventId) {
     assert(!celix_framework_isCurrentThreadTheEventLoop(fw));
-    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(5);
+    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(fw->dispatcher.genericEventTimeoutInSeconds);
     celixThreadMutex_lock(&fw->dispatcher.mutex);
-    while (celix_framework_isGenericEventInProgress(fw, eventId)) {
+    celix_framework_event_t* event = celix_framework_getGenericEvent(fw, eventId);
+    while (event) {
         celix_status_t waitStatus =
             celixThreadCondition_waitUntil(&fw->dispatcher.cond, &fw->dispatcher.mutex, &logAbsTime);
         if (waitStatus == ETIMEDOUT) {
-            fw_log(fw->logger, CELIX_LOG_LEVEL_WARNING, "Generic event with id %li not finished.", eventId);
-            logAbsTime = celixThreadCondition_getDelayedTime(5);
-        }
+            fw_log(fw->logger,

Review Comment:
   Potential use-after-free. `dispatcher.mutex` is release when waiting for `dispatcher.cond`, and thus `event` could be removed. The intention is good but we can not really do this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "Deedss (via GitHub)" <gi...@apache.org>.
Deedss commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1907683245


##########
libs/framework/src/framework_private.h:
##########
@@ -188,6 +188,8 @@ struct celix_framework {
             int nbEvent; // number of pending generic events
         } stats;
         celix_long_hash_map_t *scheduledEvents; //key = scheduled event id, entry = celix_framework_scheduled_event_t*. Used for scheduled events
+
+        double genericEventTimeout; // Timeout for printing an warning on unfinished generic events

Review Comment:
   Renamed variable to be more concise in c9bf242b0dd0d98fcdf95310acf3a36f64fdeca6



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "PengZheng (via GitHub)" <gi...@apache.org>.
PengZheng merged PR #780:
URL: https://github.com/apache/celix/pull/780


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "Deedss (via GitHub)" <gi...@apache.org>.
Deedss commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1906858795


##########
libs/framework/src/framework.c:
##########
@@ -2686,14 +2704,26 @@ static bool celix_framework_isGenericEventInProgress(celix_framework_t* fw, long
 
 void celix_framework_waitForGenericEvent(celix_framework_t* fw, long eventId) {
     assert(!celix_framework_isCurrentThreadTheEventLoop(fw));
-    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(5);
+    double logTimeoutInSeconds =
+        celix_framework_getConfigPropertyAsDouble(fw,
+                                                  CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS,
+                                                  CELIX_DEFAULT_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS,
+                                                  NULL);
+    struct timespec logAbsTime = celixThreadCondition_getDelayedTime(logTimeoutInSeconds);
     celixThreadMutex_lock(&fw->dispatcher.mutex);
+    celix_framework_event_t* event = celix_framework_getGenericEvent(fw, eventId);

Review Comment:
   Removed `celix_framework_isGenericEventInProgress` function and rely on whether the event exists.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expand logging information when genericEvent is waiting (celix)

Posted by "Deedss (via GitHub)" <gi...@apache.org>.
Deedss commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1906857277


##########
libs/framework/include/celix_constants.h:
##########
@@ -281,6 +281,21 @@ extern "C" {
  */
 #define CELIX_DEFAULT_ALLOWED_PROCESSING_TIME_FOR_SCHEDULED_EVENT_IN_SECONDS 2.0
 
+/*!
+ * @brief Celix framework environment property (named "CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS")
+ * to configure the allowed processing time for a generic event callback or a remove callback before a warning
+ * log message is printed that the processing time is too long.
+ * Should be a double value in seconds.
+ */
+#define CELIX_ALLOWED_PROCESSING_TIME_FOR_GENERIC_EVENT_IN_SECONDS                                                   \

Review Comment:
   Updated documentation and added environment variable as a C++ constexpr



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org