Skip to content

Commit

Permalink
gh-87: Fix crash caused by wait on event loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Feb 26, 2024
1 parent 5f6b628 commit c44da39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,40 @@ TEST_F(CelixBundleContextServicesTestSuite, StopSvcTrackerBeforeAsyncTrackerIsCr
EXPECT_EQ(0, cbData.count.load()); //note create tracker canceled -> no callback
}

TEST_F(CelixBundleContextServicesTestSuite, WaitForTrackerOnLoop) {
struct callback_data {
std::atomic<int> count{};
celix_bundle_context_t* ctx{nullptr};
};
callback_data cbData{};
cbData.ctx = ctx;

celix_framework_fireGenericEvent(
fw,
-1,
celix_bundle_getId(celix_framework_getFrameworkBundle(fw)),
"create tracker async",
(void*)&cbData,
[](void *data) {
auto cbd = static_cast<struct callback_data*>(data);

celix_service_tracking_options_t opts{};
opts.filter.serviceName = "test-service";
opts.trackerCreatedCallbackData = data;
opts.trackerCreatedCallback = [](void *data) {
auto* cbd = static_cast<struct callback_data*>(data);
cbd->count.fetch_add(1);
};
long trkId = celix_bundleContext_trackServicesWithOptions(cbd->ctx, &opts);
celix_bundleContext_waitForAsyncTracker(cbd->ctx, trkId);
celix_bundleContext_stopTracker(cbd->ctx, trkId);
},
nullptr,
nullptr);

celix_bundleContext_waitForEvents(ctx);
}

TEST_F(CelixBundleContextServicesTestSuite, StopBundleTrackerBeforeAsyncTrackerIsCreatedTest) {
struct callback_data {
std::atomic<int> count{};
Expand Down
1 change: 1 addition & 0 deletions libs/framework/src/bundle_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ static void celix_bundleContext_waitForTrackerInternal(celix_bundle_context_t* c
CELIX_LOG_LEVEL_WARNING,
"Cannot wait for tracker on the event loop thread. This can cause a deadlock. "
"Ignoring call.");
return;
}

bool found = false;
Expand Down

0 comments on commit c44da39

Please sign in to comment.