You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2019/12/30 07:07:07 UTC

[cayenne] branch STABLE-4.1 updated (f8975cf -> 3c0dd4e)

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

ntimofeev pushed a change to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git.


    from f8975cf  CAY-2643 ObjectSelect.prefetch(name, semantics) method creates a phantom node
     new 61a8f61  CAY-2642 EhCache memory leak due to misconfiguration   - add a warning when creating new cache entry with default config
     new 3c0dd4e  CAY-2642 EhCache memory leak due to misconfiguration  - release notes

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:
 RELEASE-NOTES.txt                                  |  1 +
 cayenne-jcache/pom.xml                             | 26 +++++++++++++++++-----
 .../apache/cayenne/jcache/JCacheQueryCache.java    |  7 ++++++
 .../jcache/unit/CacheServerRuntimeProvider.java    | 12 ++++++++++
 cayenne-jcache/src/test/resources/eh-cache.xml     | 10 +++++++++
 5 files changed, 51 insertions(+), 5 deletions(-)
 create mode 100644 cayenne-jcache/src/test/resources/eh-cache.xml


[cayenne] 02/02: CAY-2642 EhCache memory leak due to misconfiguration - release notes

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

ntimofeev pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 3c0dd4e75b4c9f7deb9b36a1cbf9d6fe9fb89f43
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Mon Dec 30 10:06:43 2019 +0300

    CAY-2642 EhCache memory leak due to misconfiguration
     - release notes
---
 RELEASE-NOTES.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 6a090f9..049568a 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -14,6 +14,7 @@ Date:
 
 Bug Fixes:
 
+CAY-2642 EhCache memory leak due to misconfiguration
 CAY-2643 ObjectSelect.prefetch(name, semantics) method creates a phantom node
 
 ----------------------------------


[cayenne] 01/02: CAY-2642 EhCache memory leak due to misconfiguration - add a warning when creating new cache entry with default config

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

ntimofeev pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 61a8f6143c82e6a4684e4259481732bb631a1a1d
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Thu Dec 26 11:46:33 2019 +0300

    CAY-2642 EhCache memory leak due to misconfiguration
      - add a warning when creating new cache entry with default config
    
    (cherry picked from commit 4720d65914fc474c2359c18d4e8414fe68022412)
---
 cayenne-jcache/pom.xml                             | 26 +++++++++++++++++-----
 .../apache/cayenne/jcache/JCacheQueryCache.java    |  7 ++++++
 .../jcache/unit/CacheServerRuntimeProvider.java    | 12 ++++++++++
 cayenne-jcache/src/test/resources/eh-cache.xml     | 10 +++++++++
 4 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/cayenne-jcache/pom.xml b/cayenne-jcache/pom.xml
index c87b8e3..e9e26a9 100644
--- a/cayenne-jcache/pom.xml
+++ b/cayenne-jcache/pom.xml
@@ -31,8 +31,9 @@
     <packaging>jar</packaging>
 
     <properties>
-        <ehcache-version>3.3.1</ehcache-version>
         <jcache-version>1.0.0</jcache-version>
+        <ehcache-version>3.8.1</ehcache-version>
+        <jaxb-api-version>2.3.1</jaxb-api-version>
     </properties>
 
     <dependencyManagement>
@@ -47,6 +48,16 @@
                 <artifactId>cache-api</artifactId>
                 <version>${jcache-version}</version>
             </dependency>
+            <dependency>
+                <groupId>javax.xml.bind</groupId>
+                <artifactId>jaxb-api</artifactId>
+                <version>${jaxb-api-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.sun.xml.bind</groupId>
+                <artifactId>jaxb-impl</artifactId>
+                <version>${jaxb-api-version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
@@ -89,13 +100,18 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.ehcache</groupId>
-            <artifactId>ehcache</artifactId>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
+            <groupId>com.sun.xml.bind</groupId>
+            <artifactId>jaxb-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ehcache</groupId>
+            <artifactId>ehcache</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
index b21b026..269c8ea 100644
--- a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
+++ b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
@@ -24,6 +24,8 @@ import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.di.BeforeScopeEnd;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.QueryMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.cache.Cache;
 import javax.cache.CacheException;
@@ -39,6 +41,8 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public class JCacheQueryCache implements QueryCache {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(QueryCache.class);
+
     @Inject
     protected CacheManager cacheManager;
 
@@ -139,6 +143,9 @@ public class JCacheQueryCache implements QueryCache {
     }
 
     protected Cache createCache(String cacheName) {
+        // Cache creation here can lead to a memory leak, see CAY-2642 for details.
+        LOGGER.warn("Creating a new JCache entry '{}'. It will be unlimited by default, and that can lead to greater memory usage or even leak. " +
+                "This entry could be configured by JCache provider-specific configuration.", cacheName);
         return cacheManager.createCache(cacheName, configurationFactory.create(cacheName));
     }
 
diff --git a/cayenne-jcache/src/test/java/org/apache/cayenne/jcache/unit/CacheServerRuntimeProvider.java b/cayenne-jcache/src/test/java/org/apache/cayenne/jcache/unit/CacheServerRuntimeProvider.java
index d9df7f6..322a5a6 100644
--- a/cayenne-jcache/src/test/java/org/apache/cayenne/jcache/unit/CacheServerRuntimeProvider.java
+++ b/cayenne-jcache/src/test/java/org/apache/cayenne/jcache/unit/CacheServerRuntimeProvider.java
@@ -19,9 +19,11 @@
 
 package org.apache.cayenne.jcache.unit;
 
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Module;
@@ -45,6 +47,16 @@ public class CacheServerRuntimeProvider extends ServerRuntimeProvider {
     protected Collection<? extends Module> getExtraModules() {
         Collection<Module> modules = new ArrayList<>(super.getExtraModules());
         modules.add(new JCacheModule());
+
+        String configURI;
+        try {
+            configURI = getClass().getResource("/eh-cache.xml").toURI().toString();
+        } catch (URISyntaxException e) {
+            throw new CayenneRuntimeException("Unable to resolve ehcache config resource URI.");
+        }
+
+        modules.add(binder -> JCacheModule
+                .contributeJCacheProviderConfig(binder, configURI));
         return modules;
     }
 }
diff --git a/cayenne-jcache/src/test/resources/eh-cache.xml b/cayenne-jcache/src/test/resources/eh-cache.xml
new file mode 100644
index 0000000..60f4455
--- /dev/null
+++ b/cayenne-jcache/src/test/resources/eh-cache.xml
@@ -0,0 +1,10 @@
+<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+        xmlns='http://www.ehcache.org/v3'
+        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">
+
+    <cache alias="g1">
+        <heap unit="entries">100</heap>
+    </cache>
+
+</config>
+