You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Robert Munteanu (JIRA)" <ji...@apache.org> on 2015/08/28 13:48:45 UTC

[jira] [Commented] (OAK-3313) Many tests leak DocumentNodeStore instances

    [ https://issues.apache.org/jira/browse/OAK-3313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14718394#comment-14718394 ] 

Robert Munteanu commented on OAK-3313:
--------------------------------------

For the record I used the following snippet to detect unclosed instances:

{code}diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
index 2c5bffd..b1ebda1 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
@@ -410,8 +410,11 @@ public final class DocumentNodeStore
     private PersistentCache persistentCache;
 
     private final DocumentNodeStoreMBean mbean;
+    
+    private final Throwable creator;
 
     public DocumentNodeStore(DocumentMK.Builder builder) {
+        creator = new Throwable().fillInStackTrace();
         this.blobStore = builder.getBlobStore();
         if (builder.isUseSimpleRevision()) {
             this.simpleRevisionCounter = new AtomicInteger(0);
@@ -599,6 +602,14 @@ public final class DocumentNodeStore
         }
         LOG.info("Disposed DocumentNodeStore with clusterNodeId: {}", clusterId);
     }
+    
+    protected void finalize() throws Throwable {
+        
+        if ( !isDisposed.get()) {
+            LOG.warn(getClass().getSimpleName() + " instance not properly disposed. Creation stack trace follows", creator);
+        }
+        
+    };
{code}

> Many tests leak DocumentNodeStore instances
> -------------------------------------------
>
>                 Key: OAK-3313
>                 URL: https://issues.apache.org/jira/browse/OAK-3313
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: core
>            Reporter: Robert Munteanu
>         Attachments: 0001-OAK-3313-Many-tests-leak-DocumentNodeStore-instances.patch
>
>
> Many tests use the {{DocumentMK.Builder}} to create {{DocumentNodeStore}} instances in tests. The cleanup is manual, either in an {{@After}} method or in the test method. The problems arise when the cleanup is forgotten or not done in a finally block. The problem appears when too many threads are started but not stopped and hit machine resource limitations.
> To solve this problem I propose using a JUnit {{@Rule}} which returns a custom {{DocumentMK.Builder}} instance which shuts down the {{DocumentNodeStore}} that it has created when the test method is finished.
> I was able to replace most of the leaks by using the {{DocumentMkBuilderProvider}} rule, as follows:
> Before:
> {code}@Test
>  public void someTest() {
>       DocumentNodeStore = new DocumentMK.Builder().getNodeStore();
>       // test code
>      store.dispose();
>   }{code}
> After:
> {code}
> @Rule
> public DocumentMkBuilderProvider builderProvider = new DocumentMkBuilderProvider();
> @Test
>  public void someTest() {
>       DocumentNodeStore = builderProvider.newBuilder().getNodeStore();
>       // test code
>   }{code}
> I haven't touched tests which did not leak DocumentNodeStore instances.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)