You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/12/21 13:35:12 UTC

[camel-karaf] branch master updated (ccbb134 -> 06cd505)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git.


    from ccbb134  CAMEL-13443: camel-test-blueprint use DOM factory from camel-support which is secured out of the box. Polished
     new b08e6fc  CAMEL-13443: camel-test-blueprint - Close file handles for PojoSRBundle bundles that are loaded from Jar via JarFile revision. Felix does not close the JarFile handle when the bundle is stopped and therefore leak file handles.
     new 06cd505  CAMEL-13443: camel-test-blueprint - upgrade tinybundles that better close resources to not leak file handles.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 components/camel-blueprint-main/pom.xml            |  4 +--
 .../camel/blueprint/CamelBlueprintHelper.java      |  8 ++---
 .../java/org/apache/camel/blueprint/MainTest.java  |  6 ++--
 components/camel-test-blueprint/pom.xml            |  4 +--
 .../test/blueprint/CamelBlueprintTestSupport.java  | 40 +++++++++++++++++++++-
 pom.xml                                            |  6 ++--
 6 files changed, 53 insertions(+), 15 deletions(-)


[camel-karaf] 01/02: CAMEL-13443: camel-test-blueprint - Close file handles for PojoSRBundle bundles that are loaded from Jar via JarFile revision. Felix does not close the JarFile handle when the bundle is stopped and therefore leak file handles.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git

commit b08e6fcef735f89c97dd4e6762a0a659ff9188f7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 21 14:01:51 2020 +0100

    CAMEL-13443: camel-test-blueprint - Close file handles for PojoSRBundle bundles that are loaded from Jar via JarFile revision. Felix does not close the JarFile handle when the bundle is stopped and therefore leak file handles.
---
 .../test/blueprint/CamelBlueprintTestSupport.java  | 40 +++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
index 7c35a87..213774d 100644
--- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
+++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
@@ -18,10 +18,12 @@ package org.apache.camel.test.blueprint;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Field;
 import java.net.URL;
 import java.nio.file.Files;
 import java.util.Arrays;
@@ -35,7 +37,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.jar.JarFile;
 
+import org.osgi.framework.Bundle;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -404,7 +408,15 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport {
             }
         }
 
-        CamelBlueprintHelper.disposeBundleContext(bundleContext);
+        // close bundle context
+        if (bundleContext != null) {
+            // remember bundles before closing
+            Bundle[] bundles = bundleContext.getBundles();
+            // close bundle context
+            CamelBlueprintHelper.disposeBundleContext(bundleContext);
+            // now close jar files from the bundles
+            closeBundleJArFile(bundles);
+        }
     }
 
     @Override
@@ -417,6 +429,32 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport {
     }
 
     /**
+     * Felix Connect leaks "open files" as a JarFile on Bundle Revision is not closed when stopping the bundle
+     * which can cause the JVM to open up too many file handles.
+     */
+    private void closeBundleJArFile(Bundle[] bundles) {
+        for (Bundle bundle : bundles) {
+            try {
+                // not all bundles is from PojoSRBundle that has a revision
+                Field field = bundle.getClass().getDeclaredField("m_revision");
+                field.setAccessible(true);
+                Object val = field.get(bundle);
+                field = val.getClass().getDeclaredField("m_jar");
+                field.setAccessible(true);
+                Object mJar = field.get(val);
+                if (mJar instanceof JarFile) {
+                    JarFile jf = (JarFile) mJar;
+                    log.debug("Closing bundle[{}] JarFile: {}", bundle.getBundleId(), jf.getName());
+                    jf.close();
+                    log.trace("Closed bundle[{}] JarFile: {}", bundle.getBundleId(), jf.getName());
+                }
+            } catch (Throwable e) {
+                // ignore
+            }
+        }
+    }
+
+    /**
      * Return the system bundle context
      */
     protected BundleContext getBundleContext() {


[camel-karaf] 02/02: CAMEL-13443: camel-test-blueprint - upgrade tinybundles that better close resources to not leak file handles.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git

commit 06cd505a0ffda667429681e0f1ee34b56ee82b83
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 21 14:34:40 2020 +0100

    CAMEL-13443: camel-test-blueprint - upgrade tinybundles that better close resources to not leak file handles.
---
 components/camel-blueprint-main/pom.xml                           | 4 ++--
 .../java/org/apache/camel/blueprint/CamelBlueprintHelper.java     | 8 ++++----
 .../src/test/java/org/apache/camel/blueprint/MainTest.java        | 6 +++---
 components/camel-test-blueprint/pom.xml                           | 4 ++--
 pom.xml                                                           | 6 +++---
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/components/camel-blueprint-main/pom.xml b/components/camel-blueprint-main/pom.xml
index b44076e..fc79a62 100644
--- a/components/camel-blueprint-main/pom.xml
+++ b/components/camel-blueprint-main/pom.xml
@@ -123,8 +123,8 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.ops4j.pax.swissbox</groupId>
-            <artifactId>pax-swissbox-tinybundles</artifactId>
+            <groupId>org.ops4j.pax.tinybundles</groupId>
+            <artifactId>tinybundles</artifactId>
         </dependency>
         <dependency>
             <groupId>commons-logging</groupId>
diff --git a/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java b/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java
index eebba97..bd85347 100644
--- a/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java
+++ b/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java
@@ -57,8 +57,8 @@ import org.apache.felix.connect.launch.BundleDescriptor;
 import org.apache.felix.connect.launch.ClasspathScanner;
 import org.apache.felix.connect.launch.PojoServiceRegistry;
 import org.apache.felix.connect.launch.PojoServiceRegistryFactory;
-import org.ops4j.pax.swissbox.tinybundles.core.TinyBundle;
-import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -365,7 +365,7 @@ public final class CamelBlueprintHelper {
     }
 
     protected static TinyBundle createConfigAdminInitBundle(String[]... configAdminPidFiles) throws IOException {
-        TinyBundle bundle = TinyBundles.newBundle();
+        TinyBundle bundle = TinyBundles.bundle();
         StringWriter configAdminInit = null;
         for (String[] configAdminPidFile : configAdminPidFiles) {
             if (configAdminPidFile == null) {
@@ -395,7 +395,7 @@ public final class CamelBlueprintHelper {
     }
 
     protected static TinyBundle createTestBundle(String name, String version, String descriptors) throws IOException {
-        TinyBundle bundle = TinyBundles.newBundle();
+        TinyBundle bundle = TinyBundles.bundle();
         for (URL url : getBlueprintDescriptors(descriptors)) {
             LOG.info("Using Blueprint XML file: " + url.getFile());
             bundle.add("OSGI-INF/blueprint/blueprint-" + url.getFile().replace("/", "-"), url);
diff --git a/components/camel-blueprint-main/src/test/java/org/apache/camel/blueprint/MainTest.java b/components/camel-blueprint-main/src/test/java/org/apache/camel/blueprint/MainTest.java
index 60d4a53..fd045a3 100644
--- a/components/camel-blueprint-main/src/test/java/org/apache/camel/blueprint/MainTest.java
+++ b/components/camel-blueprint-main/src/test/java/org/apache/camel/blueprint/MainTest.java
@@ -24,8 +24,8 @@ import java.net.URLClassLoader;
 import org.apache.aries.util.io.IOUtils;
 import org.apache.camel.ProducerTemplate;
 import org.junit.Test;
-import org.ops4j.pax.swissbox.tinybundles.core.TinyBundle;
-import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -58,7 +58,7 @@ public class MainTest {
 
     @Test
     public void testMainWithoutIncludingTestBundle() throws Exception {
-        TinyBundle bundle = TinyBundles.newBundle();
+        TinyBundle bundle = TinyBundles.bundle();
         bundle.add("OSGI-INF/blueprint/camel.xml", getClass().getResourceAsStream("main-loadfile.xml"));
         bundle.set("Manifest-Version", "2")
                 .set("Bundle-ManifestVersion", "2")
diff --git a/components/camel-test-blueprint/pom.xml b/components/camel-test-blueprint/pom.xml
index 2ff2350..66f6fb6 100644
--- a/components/camel-test-blueprint/pom.xml
+++ b/components/camel-test-blueprint/pom.xml
@@ -124,8 +124,8 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.ops4j.pax.swissbox</groupId>
-            <artifactId>pax-swissbox-tinybundles</artifactId>
+            <groupId>org.ops4j.pax.tinybundles</groupId>
+            <artifactId>tinybundles</artifactId>
         </dependency>
         <dependency>
             <groupId>commons-logging</groupId>
diff --git a/pom.xml b/pom.xml
index 819d4f4..0f11c83 100644
--- a/pom.xml
+++ b/pom.xml
@@ -237,7 +237,7 @@
         <paranamer-bundle-version>2.8_1</paranamer-bundle-version>
         <pax-cdi-version>1.0.0</pax-cdi-version>
         <pax-exam-version>4.13.4</pax-exam-version>
-        <pax-tiny-bundle-version>1.3.2</pax-tiny-bundle-version>
+        <pax-tiny-bundle-version>3.0.0</pax-tiny-bundle-version>
         <pax-logging-version>1.11.2</pax-logging-version>
         <perfmark-version>0.17.0</perfmark-version>
         <protobuf-guava-version>28.2-jre</protobuf-guava-version>
@@ -418,8 +418,8 @@
                 <version>${pax-exam-version}</version>
             </dependency>
             <dependency>
-                <groupId>org.ops4j.pax.swissbox</groupId>
-                <artifactId>pax-swissbox-tinybundles</artifactId>
+                <groupId>org.ops4j.pax.tinybundles</groupId>
+                <artifactId>tinybundles</artifactId>
                 <version>${pax-tiny-bundle-version}</version>
             </dependency>
             <dependency>