pnoltes commented on code in PR #802:
URL: https://github.com/apache/celix/pull/802#discussion_r2484816314
##########
libs/framework/src/service_tracker.c:
##########
@@ -555,6 +542,12 @@ static celix_status_t
serviceTracker_untrack(service_tracker_t* tracker, service
static void serviceTracker_untrackTracked(service_tracker_t *tracker,
celix_tracked_entry_t *tracked, int trackedSize, bool set) {
assert(tracker != NULL);
+ celixThreadMutex_lock(&tracked->mutex);
+ while (tracked->useCount > 1) {
+ celixThreadCondition_wait(&tracked->useCond, &tracked->mutex);
+ }
+ celixThreadMutex_unlock(&tracked->mutex);
+
Review Comment:
I think the check for useCount should be done after line 551
(`serviceTracker_invokeRemovingService(tracker, tracked);`).
Because otherwise there is a race. Note, and although probably not likely,
calling `serviceTracker_invokeRemovingService` and therefore code out of
control of the framework could lead to an additional retain call.
This is only the case when working directly with service tracker, instead of
through the bundle context and long tracker ids, but theoretically I think this
is a race.
I think this can be solved by moving
`serviceTracker_invokeRemovingService(tracker, tracked);` before the useCount
check.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]