Skip to content

Commit

Permalink
RemoveBoundServicesCache fix
Browse files Browse the repository at this point in the history
Fixed problem  in RemoveBoundServicesCache with stale services being left in the boundServicesCache  when sObjs.GetService call fails. sObjs.GetService can't fail in this situation. Just removed the test.
  • Loading branch information
pelliott-mathworks committed May 12, 2021
1 parent 61f8a8a commit 93b4cbf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
7 changes: 2 additions & 5 deletions compendium/DeclarativeServices/src/ComponentContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ bool ComponentContextImpl::AddToBoundServicesCache(
return true;
}

bool ComponentContextImpl::RemoveFromBoundServicesCache(
void ComponentContextImpl::RemoveFromBoundServicesCache(
const std::string& refName,
const cppmicroservices::ServiceReferenceBase& sRef)
{
Expand All @@ -238,9 +238,6 @@ bool ComponentContextImpl::RemoveFromBoundServicesCache(
bc.GetServiceObjects(ServiceReferenceU(sRef));

const auto removedService = sObjs.GetService();
if (!removedService) {
return false;
}
const auto& serviceInterface = removedService->begin()->first;
auto boundServicesCacheHandle = boundServicesCache.lock();
auto& services = boundServicesCacheHandle->at(refName);
Expand All @@ -261,7 +258,7 @@ bool ComponentContextImpl::RemoveFromBoundServicesCache(
servicesMap->at(serviceInterface));
}),
services.end());
return true;
return;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ComponentContextImpl
bool AddToBoundServicesCache(const std::string& refName
, const cppmicroservices::ServiceReferenceBase& sRef);

bool RemoveFromBoundServicesCache(const std::string& refName
void RemoveFromBoundServicesCache(const std::string& refName
, const cppmicroservices::ServiceReferenceBase& sRef);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,21 @@ void BundleOrPrototypeComponentConfigurationImpl::UnbindReference(const std::str
)
{
auto instancePairs = compInstanceMap.lock();
for (auto const& instancePair: *instancePairs)
for (auto const& instancePair : *instancePairs)
{
auto& instance = instancePair.first;
auto& context = instancePair.second;
try {
instance->InvokeUnbindMethod(refName, ref);
} catch (const std::exception&) {
GetLogger()->Log(cppmicroservices::logservice::SeverityLevel::LOG_ERROR,
"Exception received from user code while unbinding a "
"service reference.",
std::current_exception());
}

if (!context->RemoveFromBoundServicesCache(refName, ref)) {
GetLogger()->Log(cppmicroservices::logservice::SeverityLevel::LOG_ERROR,
"Failure when removing a reference from the BoundServices Cache");
}
auto& instance = instancePair.first;
auto& context = instancePair.second;
try {
instance->InvokeUnbindMethod(refName, ref);
}
catch (const std::exception&) {
GetLogger()->Log(cppmicroservices::logservice::SeverityLevel::LOG_ERROR,
"Exception received from user code while unbinding a "
"service reference.",
std::current_exception());
}

context->RemoveFromBoundServicesCache(refName, ref);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ void SingletonComponentConfigurationImpl::UnbindReference(const std::string& ref
std::current_exception());
}
auto context = GetComponentContext();
if (!context->RemoveFromBoundServicesCache(refName, ref)) {
GetLogger()->Log(cppmicroservices::logservice::SeverityLevel::LOG_ERROR,
"Failure when removing a reference from the BoundServices Cache");
}

context->RemoveFromBoundServicesCache(refName, ref);
}

void SingletonComponentConfigurationImpl::SetComponentInstancePair(InstanceContextPair instCtxtPair)
Expand Down

0 comments on commit 93b4cbf

Please sign in to comment.