jbonofre commented on code in PR #739:
URL: https://github.com/apache/camel-karaf/pull/739#discussion_r3851027125
##########
core/camel-core-osgi/src/main/java/org/apache/camel/karaf/core/OsgiTypeConverter.java:
##########
@@ -67,15 +67,15 @@ public OsgiTypeConverter(BundleContext bundleContext,
CamelContext camelContext,
this.tracker = new ServiceTracker<>(bundleContext,
TypeConverterLoader.class.getName(), this);
}
- private void ensureTrackerOpen() {
+ private synchronized void ensureTrackerOpen() {
if (!trackerOpened) {
tracker.open();
trackerOpened = true;
}
}
@Override
- public Object addingService(ServiceReference<TypeConverterLoader>
serviceReference) {
+ public synchronized Object
addingService(ServiceReference<TypeConverterLoader> serviceReference) {
LOG.trace("AddingService: {}, Bundle: {}", serviceReference,
serviceReference.getBundle());
TypeConverterLoader loader =
bundleContext.getService(serviceReference);
if (loader != null) {
Review Comment:
`bundleContext.getService()` increments the framework use-count for this
service reference. If `loader.load(delegate)` subsequently throws,
`addingService()` propagates `RuntimeCamelException`. The `ServiceTracker`
treats a throwing `addingService()` as "not tracked", so `removedService()` is
never called for this reference and `bundleContext.ungetService()` is never
invoked.
The use-count is permanently stuck above zero; the originating bundle cannot
be cleanly uninstalled for the lifetime of the OSGi framework. Fix: wrap
`loader.load()` in a try-catch and call
`bundleContext.ungetService(serviceReference)` in the catch before re-throwing.
--
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]